pieterisme Posted October 24, 2010 Posted October 24, 2010 Hi All, Basically I need to know the best way/s to accomplish this; I need to find a specific user/user name (under windows management/users and groups) then put it into a variable for use to store files and data from a machine onto a folder with the users name. Okay, so far the only way with autoit to find the username I desire is this; RunWait(@ComSpec & " /c " & 'net user > "' & @ScriptDir & 'netusers.txt"', @WorkingDir, @SW_HIDE) which outputs; User accounts for \\lptp0001 ------------------------------------------------------------------------------- Administrator Guest u0081 a0001 The command completed successfully. My guess would be to load @ScriptDir & 'netusers.txt" then somehow match the text with a mask for u#### or a#### but I dunno really how to open a file read it or match the string part. Please help, thanks in advance.
Developers Jos Posted October 24, 2010 Developers Posted October 24, 2010 (edited) What about something like this: Dim $UserSID, $oWshNetwork, $oUserAccount $objWMIService = objGet( "winmgmts:{impersonationLevel=impersonate}!//" & @ComputerName & "/root/cimv2") $oUserAccounts = $objWMIService.ExecQuery("Select Name, SID from Win32_UserAccount") For $oUserAccount In $oUserAccounts If StringLeft($oUserAccount.Name,1) = "u" or StringLeft($oUserAccount.Name,1) = "a" Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oUserAccount.Name = ' & $oUserAccount.Name & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console EndIf Next Edited October 24, 2010 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Legacy99 Posted October 24, 2010 Posted October 24, 2010 Seconded, You beat me to it WMI is your friend. For more examples look up Scriptomatic.
GEOSoft Posted October 24, 2010 Posted October 24, 2010 He may also have to check that the WMI service is not disabled. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
pieterisme Posted October 24, 2010 Author Posted October 24, 2010 What about something like this: Dim $UserSID, $oWshNetwork, $oUserAccount $objWMIService = objGet( "winmgmts:{impersonationLevel=impersonate}!//" & @ComputerName & "/root/cimv2") $oUserAccounts = $objWMIService.ExecQuery("Select Name, SID from Win32_UserAccount") For $oUserAccount In $oUserAccounts If StringLeft($oUserAccount.Name,1) = "u" or StringLeft($oUserAccount.Name,1) = "a" Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oUserAccount.Name = ' & $oUserAccount.Name & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console EndIf Next Sweet guys fasts replies, also thanks Legacy99 for the WMI site I will look it up when I get more time always willing to learn However I am getting a variable empty issue when trying to assign to a string and remove the a or u prefix from the user account number Dim $UserSID, $oWshNetwork, $oUserAccount $objWMIService = objGet( "winmgmts:{impersonationLevel=impersonate}!//" & @ComputerName & "/root/cimv2") $oUserAccounts = $objWMIService.ExecQuery("Select Name, SID from Win32_UserAccount") For $oUserAccount In $oUserAccounts If StringLeft($oUserAccount.Name,1) = "u" or StringLeft($oUserAccount.Name,1) = "a" And $oUserAccount.Name <> "Administrator" Then $ua_num = ($oUserAccount.Name) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oUserAccount.Name = ' & $oUserAccount.Name & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console $pc_number = StringTrimLeft($ua_num, 1) MsgBox(16, "mydebug", $pc_number) EndIf Next
GEOSoft Posted October 24, 2010 Posted October 24, 2010 Try it this way. Dim $UserSID, $oWshNetwork, $oUserAccount $objWMIService = objGet( "winmgmts:{impersonationLevel=impersonate}!//" & @ComputerName & "/root/cimv2") $oUserAccounts = $objWMIService.ExecQuery("Select Name, SID from Win32_UserAccount") For $oUserAccount In $oUserAccounts If (StringLeft($oUserAccount.Name,1) = "u" or StringLeft($oUserAccount.Name,1) = "a") And $oUserAccount.Name <> "Administrator" Then $ua_num = ($oUserAccount.Name) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oUserAccount.Name = ' & $oUserAccount.Name & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console $pc_number = StringTrimLeft($ua_num, 1) MsgBox(16, "mydebug", $pc_number) EndIf Next George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now