Briandr Posted November 4, 2015 Share Posted November 4, 2015 (edited) Hi,The RegWrite statements referenced below should run if the detected model is one of the laptops listed. I get the reg entries written for desktops. Do I need an exit or perhaps I don't need the references to the desktop computers at all? What is odd is there 3 Reg Write statements and when run 2 Reg Writes get written to the registry of a desktop. Help much appreciated. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=C:\Program Files (x86)\AutoIt3\Icons\dell_icon.ico #AutoIt3Wrapper_Outfile=ModelWrapper.exe #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Res_Comment=Install wrapper #AutoIt3Wrapper_Res_Description=Install wrapper #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <File.au3> #include <Constants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Dim $ChassisType, $Model $LogDirectory = @WindowsDir & "\Dell\KACE" $ModuleName = @ScriptName $ModuleName = StringSplit($ModuleName, ".") $ModuleName = $ModuleName[1] $Log = $LogDirectory & "\" & $ModuleName & ".log" $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) _FileWriteLog($Log, $ModuleName & " module called.") _Win32_ComputerSystem() _HPConnectionManagerCustom() 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 _HPConnectionManagerCustom() If $Model = "HP EliteBook 2530p" Or $Model = "HP EliteBook 2540p" Or $Model = "HP EliteBook 2560p" Or $Model = "HP EliteBook 2570p" Or $Model = "HP Compaq 6530b (FG996AW#ABA)" _ Or $Model = "HP ProBook 6455b" Or $Model = "HP ProBook 6465b" Or $Model = "HP ProBook 6475b" Or $Model = "HP ProBook 645 G1" Or $Model = "HP EliteBook Folio 9470m" _ Or $Model = "HP EliteBook Folio 9480m" Or $Model = "HP EliteBook Revolve 810 G1" Or $Model = "HP EliteBook Revolve 810 G2" Or $Model = "HP EliteBook Revolve 810 G3" _ Or $Model = "HP EliteBook 840 G2" Then ; Is laptop, write values to registry for HP Connection Manager RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowInitialStatus", "REG_SZ", "False") RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowConnectivity", "REG_SZ", "False") RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowPower", "REG_SZ", "False") ElseIf $Model = "HP Compaq dc7900 Small Form Factor" Or $Model = "HP Compaq 8000 Elite SFF PC" Or $Model = "HP Compaq 8200 Elite SFF PC" Or $Model = "HP Compaq Elite 8300 SFF" _ Or $Model = "HP EliteDesk 800 G1 DM" Or $Model = "HP EliteDesk 800 G1 SFF" Then ; 'Is Desktop, exit function and script. EndIf EndFunc ;==>_HPConnectionManagerCustom Edited November 4, 2015 by Briandr Link to comment Share on other sites More sharing options...
JohnOne Posted November 4, 2015 Share Posted November 4, 2015 Perhaps one of the keys does not exist.AutoIt has in place macros to help you debug these problems, one is named @error, look it up under the regwrite function in the help file. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted November 4, 2015 Share Posted November 4, 2015 (edited) You can have just an IF since your doing nothing with the desktops.If $Model = "Laptop" or $Model = "Laptop2" ThenWrite Reg KeysEndIfThat would trim your script down some. I imagine your error is in your line continuation you do not have the "&" neededIt should look like this:MsgBox(0, "", "This Line Will" & _ "Continue Down Below")Also based on what I see you can probably really trim down the script with a StringInStr() or RegEx but I do not want to get off topic.$Model = InputBox("Test", "Enter Model") _HPConnectionManagerCustom() _HPConnectionManagerCustomRegex() Func _HPConnectionManagerCustom() If StringInStr($Model, "EliteBook") OR StringInStr($Model, "ProBook") OR StringInStr($Model, "6530b") Then MsgBox(0, "", "Found " & $Model) ;RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowInitialStatus", "REG_SZ", "False") ;RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowConnectivity", "REG_SZ", "False") ;RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowPower", "REG_SZ", "False") EndIf EndFunc Func _HPConnectionManagerCustomRegex() If StringRegExp($Model, "(?i)(EliteBook|ProBook|6530b)") Then MsgBox(0, "", "Found " & $Model) ;RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowInitialStatus", "REG_SZ", "False") ;RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowConnectivity", "REG_SZ", "False") ;RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowPower", "REG_SZ", "False") EndIf EndFunc Edited November 4, 2015 by ViciousXUSMC Link to comment Share on other sites More sharing options...
Briandr Posted November 4, 2015 Author Share Posted November 4, 2015 (edited) What threw me was when I debugged it came back clean and it compiled clean. That is really a cool trick with the StringInStr. I want to say that when I ran this before outside a typical desktop management suite (i.e., Altiris or SCCM) it ran fine. When I ran it inside as a so called task sequence that is when I noticed the issue with the reg entries on desktop computers.I also chose the route I did because I have one particular tablet / laptop combo which WMI was returning a weird value on. So I decided not to do a WMI statmenet referencing the chassis type. Edited November 4, 2015 by Briandr Link to comment Share on other sites More sharing options...
Briandr Posted November 5, 2015 Author Share Posted November 5, 2015 (edited) This is what I ended up with and the logging results don't yield alot of clues. Maybe the logging needs to change. The inconsistency of this running inside of a SCCM type environment and failing. Then working outside that particular environment and working makes me wonder is there a timing issue or something? What I am wondering is do I really have an error? I can't tell and when it does write to the wrong registry why does it cut out after the 2nd Reg Write? Why not just write all 3 lines. Something weird here. Ideas appreciated and Thanks.expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=C:\Program Files (x86)\AutoIt3\Icons\dell_icon.ico #AutoIt3Wrapper_Outfile=ModelWrapper.exe #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Res_Comment=Install wrapper #AutoIt3Wrapper_Res_Description=Install wrapper #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <File.au3> #include <Constants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Dim $ChassisType, $Model $LogDirectory = @WindowsDir & "\Dell\KACE" $ModuleName = @ScriptName $ModuleName = StringSplit($ModuleName, ".") $ModuleName = $ModuleName[1] $Log = $LogDirectory & "\" & $ModuleName & ".log" $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) _FileWriteLog($Log, $ModuleName & " module called.") _Win32_ComputerSystem() _HPConnectionManagerCustom() 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 _HPConnectionManagerCustom() If StringInStr($Model, "EliteBook") OR StringInStr($Model, "ProBook") OR StringInStr($Model, "6530b") Then RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowInitialStatus", "REG_SZ", "False") RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowConnectivity", "REG_SZ", "False") RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowPower", "REG_SZ", "False") EndIf EndFunc ;==>_HPConnectionManagerCustom2015-11-05 09:48:09 : HPConnMgrPref module called.2015-11-05 09:48:09 : Model: HP Elitedesk 800 G1 SFF Edited November 5, 2015 by Briandr Link to comment Share on other sites More sharing options...
JohnOne Posted November 5, 2015 Share Posted November 5, 2015 I'm baffled why you are having a problem with a function but refuse to even consider its return and error values. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Briandr Posted November 5, 2015 Author Share Posted November 5, 2015 I been looking at the help files and google trying to find how to code it so I can additional return values. The last 2 lines were return values. So the code and lack thereof it needs tweaking to get error values (assuming they exist) or better return values.I know you guys don't have alot of patience and don't give code away for free, but I am checking. I just don't know Autoit well enough to whip something up as fast as one of you guys.No disrespect intended. I also fully concede the desktop management suite is the issue. I have seen perfectly good pieces of code work outside it, but not in it. Link to comment Share on other sites More sharing options...
JohnOne Posted November 5, 2015 Share Posted November 5, 2015 RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowInitialStatus", "REG_SZ", "False") ConsoleWrite("1 " & @error & @LF) RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowConnectivity", "REG_SZ", "False") ConsoleWrite("2 " & @error & @LF) RegWrite("HKEY_CURRENT_USER\Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowPower", "REG_SZ", "False") ConsoleWrite("3 " & @error & @LF) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Briandr Posted November 6, 2015 Author Share Posted November 6, 2015 (edited) As it relates to If StringInStr($Model, "EliteBook")Is that going to search specifically for what is in quotes? I would assume so and that is not a wildcard parameter set to search for anything with that word in it.If I am looking at the help file example right perhaps I need to change to If StringInStr($Model, "Elite", "EliteBook")I ask that question because some desktop models have Elite it the name just like the laptop models. I am just trying to tweak this unless I don't need to do as the original example was correct. Oh and whenever or wherever I ran the modified that does the console write I did not see any ouput to the screen which is a good sign I think as there was no errors. Thanks Edited November 6, 2015 by Briandr 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