GregThompson Posted February 5, 2007 Share Posted February 5, 2007 I would like to write a script that does the following: Read an INF Store a variable Use the stored variable in a registry key So, I can do all of this in normal AutoIT, but I don't want to use the RunAS command to write the registry entries. I'd like to use the Com Obj stuff and the Impersonate command, then write the registry keys. Can someone point me in the right direction? I've been searching the site for example, can't find any, and I've been reading vbs sites/tutorials, and can't get a decent piece of code to work from. Link to comment Share on other sites More sharing options...
evilertoaster Posted February 5, 2007 Share Posted February 5, 2007 Google these- ImpersonateLoggedOnUser LogonUser RevertToSelf The process is you logon a user with the 'logonuser' function pass the token to the 'impersonteloggedonuser' and the use 'reverttoself' to go back to normal. details could take a bit of searching but theres a start Link to comment Share on other sites More sharing options...
GregThompson Posted February 5, 2007 Author Share Posted February 5, 2007 (edited) Google these- ImpersonateLoggedOnUser LogonUser RevertToSelf The process is you logon a user with the 'logonuser' function pass the token to the 'impersonteloggedonuser' and the use 'reverttoself' to go back to normal. details could take a bit of searching but theres a start Hrm, I appreciate the response, but I'm not sure what this is? I was under the impression I had to use the WMI stuff, like $strComputer = "." $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\CIMV2") And then use something like objwmiservice.regwrite, etc, etc Edited February 5, 2007 by GregThompson Link to comment Share on other sites More sharing options...
ptrex Posted February 6, 2007 Share Posted February 6, 2007 @GregThompson This example sets the proxy settings of your browser. Const $HKEY_CURRENT_USER = 0x80000001 $strComputer = "." $objRegistry = ObjGet("winmgmts:\\" & $strComputer & "\root\default:StdRegProv") $strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" $strValueName = "ProxyEnable" $dwValue = 1 $objRegistry.SetDWORDValue ($HKEY_CURRENT_USER, $strKeyPath, $strValueName, $dwValue) This should you get going. You don't need "impersonation" if you are the Admin who is running the scripts. regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
evilertoaster Posted February 6, 2007 Share Posted February 6, 2007 Hrm, I appreciate the response, but I'm not sure what this is? I was under the impression I had to use the WMI stuff, like $strComputer = "."$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\CIMV2")And then use something like objwmiservice.regwrite, etc, etcI don't know about that. i know you an use the method i mentioned. They are dll functions you'd use with dll call (Advapi32.dll). Once the impersonation is made, the program runs under that identity untill you switch back...any commands you use untill you switch bcak are ran under the impersonated identity... i have never done the WMI way if there is one so i cant speak to it. Link to comment Share on other sites More sharing options...
GregThompson Posted February 7, 2007 Author Share Posted February 7, 2007 @GregThompson This example sets the proxy settings of your browser. Const $HKEY_CURRENT_USER = 0x80000001 $strComputer = "." $objRegistry = ObjGet("winmgmts:\\" & $strComputer & "\root\default:StdRegProv") $strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" $strValueName = "ProxyEnable" $dwValue = 1 $objRegistry.SetDWORDValue ($HKEY_CURRENT_USER, $strKeyPath, $strValueName, $dwValue) This should you get going. You don't need "impersonation" if you are the Admin who is running the scripts. regards, ptrex PTRex, thanks, assume that I'm NOT the admin though. The deal is that we want to push out a script without credentials of an Admin, to impersonate one and make the registry settings for our WSUS pilot group. Link to comment Share on other sites More sharing options...
ptrex Posted February 8, 2007 Share Posted February 8, 2007 @GregThompson Maybe this will get you get going. expandcollapse popup#include <date.au3> $strComputer = "." $objWMIService = ObjGet("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colItems = $objWMIService.ExecQuery _ ("Select * from Win32_NetworkLoginProfile") For $objItem in $colItems $dtmWMIDate = $objItem.AccountExpires $strReturn = WMIDateStringToDate($dtmWMIDate) Consolewrite ("Account Expires: " & $strReturn & @CR) Consolewrite ("Authorization Flags: " & $objItem.AuthorizationFlags & @CR) Consolewrite ("Bad Password Count: " & $objItem.BadPasswordCount & @CR) Consolewrite ("Caption: " & $objItem.Caption & @CR) Consolewrite ("CodePage: " & $objItem.CodePage & @CR) Consolewrite ("Comment: " & $objItem.Comment & @CR) Consolewrite ("Country Code: " & $objItem.CountryCode & @CR) Consolewrite ("Description: " & $objItem.Description & @CR) Consolewrite ("Flags: " & $objItem.Flags & @CR) Consolewrite ("Full Name: " & $objItem.FullName & @CR) Consolewrite ("Home Directory: " & $objItem.HomeDirectory & @CR) Consolewrite ("Home Directory Drive: " & $objItem.HomeDirectoryDrive & @CR) $dtmWMIDate = $objItem.LastLogoff $strReturn = WMIDateStringToDate($dtmWMIDate) Consolewrite ("Last Logoff: " & $strReturn & @CR) $dtmWMIDate = $objItem.LastLogon $strReturn = WMIDateStringToDate($dtmWMIDate) Consolewrite ("Last Logon: " & $strReturn & @CR) Consolewrite ("Logon Hours: " & $objItem.LogonHours & @CR) Consolewrite ("Logon Server: " & $objItem.LogonServer & @CR) Consolewrite ("Maximum Storage: " & $objItem.MaximumStorage & @CR) Consolewrite ("Name: " & $objItem.Name & @CR) Consolewrite ("Number Of Logons: " & $objItem.NumberOfLogons & @CR) Consolewrite ("Password Age: " & $objItem.PasswordAge & @CR) $dtmWMIDate = $objItem.PasswordExpires $strReturn = WMIDateStringToDate($dtmWMIDate) Consolewrite ("Password Expires: " & $strReturn & @CR) Consolewrite ("Primary Group ID: " & $objItem.PrimaryGroupId & @CR) Consolewrite ("Privileges: " & $objItem.Privileges & @CR) Consolewrite ("Profile: " & $objItem.Profile & @CR) Consolewrite ("Script Path: " & $objItem.ScriptPath & @CR) Consolewrite ("Setting ID: " & $objItem.SettingID & @CR) Consolewrite ("Units Per Week: " & $objItem.UnitsPerWeek & @CR) Consolewrite ("User Comment: " & $objItem.UserComment & @CR) Consolewrite ("User Id: " & $objItem.UserId & @CR) Consolewrite ("User Type: " & $objItem.UserType & @CR) Consolewrite ("Workstations: " & $objItem.Workstations & @CR) Next Func WMIDateStringToDate($dtmWMIDate) Local $Return If Not $dtmWMIDate ="" Then Return (StringMid($dtmWMIDate, 5, 2) & "/" & _ StringMid($dtmWMIDate, 7, 2) & "/" & StringLeft($dtmWMIDate, 4) _ & " " & StringMid($dtmWMIDate, 9, 2) & ":" & StringMid($dtmWMIDate, 11, 2) & ":" & StringMid($dtmWMIDate,13, 2)) Return $Return Endif EndFunc Enjoy!! ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
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