Briandr Posted September 10, 2015 Posted September 10, 2015 (edited) expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=..\..\..\..\..\..\..\..\Program Files (x86)\AutoIt3\Icons\dell.ico #AutoIt3Wrapper_Outfile=Cleanup.exe #AutoIt3Wrapper_Res_Fileversion=1.0.0.14 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p #AutoIt3Wrapper_Res_LegalCopyright=Dell Inc. #AutoIt3Wrapper_Res_Language=1033 #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Allow_Decompile=n #include <File.au3>; File functions #include <Array.au3>; Array functions #include <Process.au3>; Array functions #include <AccessCom.au3> #include <Constants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Dim $ArchType, $ProgramFileDir, $CurrentDomain, $Model $LogDirectory = @WindowsDir & "\Dell\KACE" $ModuleName = @ScriptName $ModuleName = StringSplit($ModuleName, ".") $ModuleName = $ModuleName[1] $Log = $LogDirectory & "\" & $ModuleName & ".log" $StatusCode = 0 $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $StrComputer = "localhost" If Not FileExists($LogDirectory) Then DirCreate($LogDirectory) ;Creates path if does not exist If FileExists($Log) Then FileDelete($Log) ;Start with new log _FileWriteLog($Log, $ModuleName & " module called") _GetOSArch() ;determine os arch _GetDomain() ;get current domain _ForcepadCustom() Func _GetOSArch() ; Get Architecture Type If @OSArch = "X86" Then $ProgramFileDir = @HomeDrive & "\Program Files" $ArchType = "" _FileWriteLog($Log, "OS is 32-bit:") _FileWriteLog($Log, "Program Files Directory is: " & $ProgramFileDir) Else $ProgramFileDir = @HomeDrive & "\Program Files (x86)" $ArchType = "64" _FileWriteLog($Log, "OS is 64-bit:") _FileWriteLog($Log, "Program Files Directory is: " & $ProgramFileDir) EndIf EndFunc ;==>_GetOSArch Func _GetDomain() ;gets domain of current computer $CurrentDomain = '' $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems $CurrentDomain = $objItem.Domain Next EndIf _FileWriteLog($Log, "Current PC Domain: " & $CurrentDomain) Return $CurrentDomain EndFunc ;==>_GetDomain Func _Win32_ComputerSystem() ;Get General PC Info $objWMIService = ObjGet("winmgmts:\\" & $StrComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems ;$DOMAIN = $objItem.Domain $Manufacturer = $objItem.Manufacturer $Model = $objItem.Model _FileWriteLog($Log, "Model: " & $Model) ;$MachineName = $objItem.Name ;$NumberOfProcessors = $objItem.NumberOfProcessors ;$PartOfDomain = $objItem.PartOfDomain ;$MEM = Round($objItem.TotalPhysicalMemory / 1024 / 1024, 0) Next EndIf EndFunc ;==>_Win32_ComputerSystem Func _ForcepadCustom() If $Model = "HP EliteBook Folio 1040 G2" Then _FileWriteLog($Log, "Removing registry entries for Forcepad shortcut for: HP EliteBook Folio 1040 G2") RegDelete("HKLM" & $ArchType & "\SOFTWARE\Synaptics\SynTPEnh\ShortcutConfig", "Shortcut1") RegDelete("HKLM" & $ArchType & "\SOFTWARE\Synaptics\SynTPEnh\ShortcutConfig", "Shortcut2") RegDelete("HKLM" & $ArchType & "\SOFTWARE\Synaptics\SynTPEnh\ShortcutConfig", "Shortcut3") RegDelete("HKLM" & $ArchType & "\SOFTWARE\Synaptics\SynTPEnh\ShortcutConfig", "Shortcut4") _FileWriteLog($Log, "Registry entries for Forcepad shortcut have been removed") EndIf EndFunc ;==>_ForcepadCustomThe issue here is within the function _ForcepadCustom(). If I try to detect the model prior to logging then deleting the registry values then nothing happens. If I get rid of the If-EndIf statement it works. Do I need to expand on the If-EndIf with an Else? I didn't think I would need one. Could be wrong. I also tried with and without #RequireAdmin. No difference.Help appreciated. Edited September 10, 2015 by Briandr
ViciousXUSMC Posted September 10, 2015 Posted September 10, 2015 (edited) Did you try to see the value of $Model maybe its not matching your string. If its different (even a little bit) then nothing in that If statement will execute. Since you said its working without the IF/EndIf I would imagine its because your statement is not true. Also your first two If statements having to do with the log/directory.You can just create the directory rather than checking for it first, if it already exists it just will not do anything. (or use $FO_CREATEPATH with FileOpen()For the _FileWriteLog() since your using it over and over, and deleting any old logs early on. You can just use FileOpen() with $FO_OVERWRITE then call the handle and use FileClose() at the end it should be more efficient that way rather than opening/closing the file each time. Edited September 10, 2015 by ViciousXUSMC
Briandr Posted September 11, 2015 Author Posted September 11, 2015 (edited) I found my own error. I neglected to reference the function _Win32_ComputerSystem() at the top with the rest._GetOSArch() ;determine os arch _GetDomain() ;get current domain _ForcepadCustom() _Win32_ComputerSystem()Once I did then everything seemed to be fine. Code probably could still use some cleaning up but it works now. Edited September 11, 2015 by Briandr
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