In answer to your question: Yes, it is possible to do this
with VB scripts or with batch files.
First, when you attempt to access HKCU with a script, it pulls the HKCU for
the account that is running the script. For example, your name is Bob and
you are trying to pull the HKCU for Sue on computer B. When your script
runs, it doesn't pull the HKCU for Sue, even though she's logged on. It will
pull your HKCU as if you were logged on.
To get around this:
First, query the computer for the current logged on user.
Next, get the SID for that account.
Then access HKU (HKEY_USERS) and start with that SID.
If you need code to do any of this, let me know!
-Corey Thomas
"Monitor" <nos...@spam.com> wrote in message
news:%23QWJo1E...@TK2MSFTNGP03.phx.gbl...
"Corey Thomas - MCSE/MCSA/MCDBA" <Corey Thomas -
MCSE/MCSA/MC...@discussions.microsoft.com> wrote in message
news:A9FC5517-EF92-4051...@microsoft.com...
Here is some sample code:
Const sMode = "1" '1: AutoLogon=on, 0: AutoLogon=off
Const sComputer="Nalle"
Const HKEY_LOCAL_MACHINE = &H80000002 'HKLM hive
Const sKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
Const sValueName = "AutoAdminLogon"
Dim oReg, sCurrValue, iResult, sSuccess, sFailure, sText
Dim LF: LF = Chr(10)
On Error Resume Next
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
sComputer & "\root\default:StdRegProv")
If Error > 0 Then
MsgBox "Cannot reach this machine!", 0, "Set AutoLogon on " & sComputer
WScript.Quit
End If
On Error Goto 0
oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyPath, sValueName, sCurrValue
iResult = oReg.SetStringValue (HKEY_LOCAL_MACHINE, sKeyPath, sValueName,
sMode)
'==================================================================
Function GetCurrentUser(strComputer)
'Input: strComputer = machine to query
'Output: Current User as domain\logon
'On Error Resume Next
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process
Where Name = 'explorer.exe'")
For Each objProcess in colProcessList
objProcess.GetOwner strUserName, strUserDomain
'Wscript.Echo strComputer & ",Is logged into by " & strUserDomain & "\"
& strUserName
Next
GetCurrentUser = strUserDomain & "\" & strUserName
End Function
'==================================================================
Then use the current user to get the SID:
'==================================================================
Function GetSIDFromUser(UserName)
'Input: UserName as domain\logon
'Output: SID
Dim DomainName, Result, WMIUser
If InStr(UserName, "\") > 0 Then
DomainName = Mid(UserName, 1, InStr(UserName, "\") - 1)
UserName = Mid(UserName, InStr(UserName, "\") + 1)
Else
DomainName = CreateObject("WScript.Network").UserDomain
End If
On Error Resume Next
Set WMIUser = GetObject("winmgmts:{impersonationlevel=impersonate}!" _
& "/root/cimv2:Win32_UserAccount.Domain='" & DomainName & "'" _
& ",Name='" & UserName & "'")
If Err = 0 Then Result = WMIUser.SID Else Result = ""
On Error GoTo 0
GetSIDFromUser = Result
End Function
'==================================================================
Now you have the SID, find the key you need in HKU\SID\... and that will be
the actual current user for that machine.
U can check for the key existance using....
HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
&strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\RealNetworks\RealPlayer"
if oReg.EnumKey (HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys) = 0 then
'key exists..
'do this...
end if
Hi,
I want to Check for a registry key in a remote machine and if it exists
grep the key and run uninstaller of an app.
Is it possible to have a batch script that checks a remote PC (running
XP pro) tosee whether a particular registry key exists on the remote PC?
Thanks in advance,
Murali.
*** Sent via Developersdex http://www.developersdex.com ***
Are you looking for a batch file or a VB Script solution? If it's a VB
Script solution then this link should help:
http://www.microsoft.com/technet/scriptcenter/guide/sas_reg_famr.mspx?mfr=True.
Replace [strComputer = "."] with [strComputer = "ComputerName" to query a
remote machine.
If you're after a batch file solution then here is an example that will do
the trick: reg query HKEY_CURRENT_USER\Console. To query a remote machine,
use psexec.exe (www.sysinternals.com) to invoke reg.exe.