Bartoooo
-
Total Posts
:
18
- Scores: 0
-
Reward points
:
0
- Joined: 12/12/2011
-
Status: online
|
Get currenlty logged on users SID
Monday, December 12, 2011 2:33 AM
( permalink)
Hello! I would like to remove a regkey from the current logged user, is ther a way of doing this? I am stuck at getting grab of the SID of the user as you can see in the pic below. http://img403.imageshack.us/img403/8598/registerx.jpg For example: HKEY_USERS/<SID of Logged In User>/Software/<Program Folder> HKEY_USERS/S-1-5-21-23635808756-545454-234324/Software/McAfee Any one knows how to accomplish this? // Bartoooo
|
|
|
|
Wakawaka
-
Total Posts
:
456
- Scores: 23
-
Reward points
:
0
- Joined: 8/27/2009
-
Status: offline
|
Re:Get currenlty logged on users SID
Monday, December 12, 2011 3:11 AM
( permalink)
Using WMI and the Win32_Process class, query the owner of the of the 'explorer.exe' process and then use the .GetOwnerSID method of the process class.
|
|
|
|
59cobalt
-
Total Posts
:
969
- Scores: 91
-
Reward points
:
0
- Joined: 7/17/2011
-
Status: offline
|
Re:Get currenlty logged on users SID
Monday, December 12, 2011 7:20 AM
( permalink)
Why Win32_Process? Set net = CreateObject("WScript.Network")
Set wmi = GetObject("winmgmts://./root/cimv2")
WScript.Echo wmi.Get("Win32_UserAccount.Name='" & net.UserName & "',Domain='" & net.UserDomain & "'").SID
<message edited by 59cobalt on Monday, December 12, 2011 7:21 AM>
|
|
|
|
Wakawaka
-
Total Posts
:
456
- Scores: 23
-
Reward points
:
0
- Joined: 8/27/2009
-
Status: offline
|
Re:Get currenlty logged on users SID
Monday, December 12, 2011 12:41 PM
( permalink)
The Win32_Process can be easily used to remotely get the same information. I don't like making a script that can only be ran on the local computer and not remotely.
|
|
|
|
Bartoooo
-
Total Posts
:
18
- Scores: 0
-
Reward points
:
0
- Joined: 12/12/2011
-
Status: online
|
Re:Get currenlty logged on users SID
Tuesday, December 13, 2011 2:07 AM
( permalink)
Wakawaka Using WMI and the Win32_Process class, query the owner of the of the 'explorer.exe' process and then use the .GetOwnerSID method of the process class. Great Idea! Not just sure on how to do it :) This is my code, The only thing it returns is "0". And from what i can see from the link below it's a Successfull completion, But how do i get the actual SID ? http://msdn.microsoft.com...aa390459(v=VS.85).aspx strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Process WHERE Caption='explorer.exe'") For Each objItem in colItems Wscript.Echo "Name: " & objItem.Caption & vbCr & _ "Process SID: " & objItem.GetOwnerSid(objItem.Caption) Next Thanks in advanced! // Bartoooo
|
|
|
|
Bartoooo
-
Total Posts
:
18
- Scores: 0
-
Reward points
:
0
- Joined: 12/12/2011
-
Status: online
|
Re:Get currenlty logged on users SID
Tuesday, December 13, 2011 2:17 AM
( permalink)
This worked for me! Its just that i need to run the VBscript as Administrator but return the SID for the logged on user but this return the SID for the user that runs the script. In this case the administrator. Any good idea on how to fix that problem? This script will be runned localy so it does not mattes if i can run i remote or now :) Thanks in advance!
|
|
|
|
Wakawaka
-
Total Posts
:
456
- Scores: 23
-
Reward points
:
0
- Joined: 8/27/2009
-
Status: offline
|
Re:Get currenlty logged on users SID
Tuesday, December 13, 2011 2:36 AM
( permalink)
Firstly, you are using the GetOwnerSID method wrong. The GetOwnerSID method doesn't actually return a value. You have to call it by itself and pass it a parameter that it loads with the SID. Dim sUserSID
...
objItem.GetOwnerSID sUserSID
...
Msgbox sUserSID Secondly, I would use the Name property instead of the caption property. "SELECT * FROM Win32_Process WHERE Name='explorer.exe'"
<message edited by Wakawaka on Tuesday, December 13, 2011 2:39 AM>
|
|
|
|
Bartoooo
-
Total Posts
:
18
- Scores: 0
-
Reward points
:
0
- Joined: 12/12/2011
-
Status: online
|
Re:Get currenlty logged on users SID
Tuesday, December 13, 2011 3:05 AM
( permalink)
Wakawaka Firstly, you are using the GetOwnerSID method wrong. The GetOwnerSID method doesn't actually return a value. You have to call it by itself and pass it a parameter that it loads with the SID. Dim sUserSID
...
objItem.GetOwnerSID sUserSID
...
Msgbox sUserSID Secondly, I would use the Name property instead of the caption property. "SELECT * FROM Win32_Process WHERE Name='explorer.exe'" Big thanks Wakawaka! Final Code! Option ExplicitDim strComputerDim objWMIServiceDim objItemDim colItemsDim sUserSID
strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Process WHERE Name='explorer.exe'")
For Each objItem in colItems objItem.GetOwnerSID sUserSID MsgBox "Name: " & objItem.Name & vbCr & _ "Process SID: " & sUserSIDNext EDIT: My Line breakes does not work in the [ Code ] ! :)
<message edited by Bartoooo on Tuesday, December 13, 2011 3:09 AM>
|
|
|
|
KnkT9
-
Total Posts
:
5
- Scores: 0
-
Reward points
:
0
- Joined: 12/19/2011
-
Status: offline
|
Re:Get currenlty logged on users SID
Thursday, December 22, 2011 11:42 AM
( permalink)
Hello, Add to this, does any one knows how to get the "explorer.exe" owner. and by owner i mean the logged on user ?
<message edited by KnkT9 on Thursday, December 22, 2011 11:50 AM>
|
|
|
|
Wakawaka
-
Total Posts
:
456
- Scores: 23
-
Reward points
:
0
- Joined: 8/27/2009
-
Status: offline
|
Re:Get currenlty logged on users SID
Friday, December 23, 2011 12:08 AM
( permalink)
Use the GetOwner method of the Process object.
|
|
|
|