Windows Vista Forums

Problems with VBScript - RegRead when running as a service

  1. #1


    Brandon Guest

    Problems with VBScript - RegRead when running as a service

    I am working on a script that runs under a custom installation
    utility, which is running as a service. To get the current user name
    the script executes this command:

    str_Acct_Name_Val = "HKCU\Software\Microsoft\Windows\CurrentVersion
    \Explorer\Logon User Name"
    str_Acct_Name = RegRead(str_Acct_Name_Val)

    When I run the script from the command prompt, it can read that value
    just fine (under an administrator account). When the value is
    attempted to be read with service/local system privileges, the read
    fails.

    What is the problem here?

      My System SpecsSystem Spec

  2. #2


    Brandon Guest

    Re: Problems with VBScript - RegRead when running as a service

    Some additional information. When running as a service calling the
    current user name returns "SYSTEM" and my guess is that HKCU doesn't
    "exist" under the view of the SYSTEM, since there is technically no
    current user. There is a user logged in at the time, but not in the
    scope of the running script. Maybe there is somewhere in HKLM I could
    find the currently logged on user?

      My System SpecsSystem Spec

  3. #3


    LikeToCode Guest

    RE: Problems with VBScript - RegRead when running as a service

    So why not query the owner of a specific process like "explorer.exe".

    Option Explicit
    Dim objWMIService, colProcessList, objProcess, colProperties
    Dim strUserDomain, strUserName
    Set objWMIService =
    GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")
    For Each objProcess in colProcessList
    If objProcess.name = "explorer.exe" Then
    colProperties = objProcess.GetOwner(strUserName,strUserDomain)
    Wscript.Echo "The current User is: " & strUserDomain & "\" &
    strUserName & "."
    End If
    Next



      My System SpecsSystem Spec


Problems with VBScript - RegRead when running as a service
Similar Threads
Thread Forum
Running exchange powershell command from vbscript VB Script
Running exchange powershell command from vbscript PowerShell
VBScript to get the Dell Service Tag.....I know...I know.... VB Script
VBScript problem in running Stored Query VB Script
Running an executable within a VBscript VB Script