Jump to content

zorphnog

Active Members
  • Posts

    443
  • Joined

  • Last visited

About zorphnog

  • Birthday 01/24/1983

Recent Profile Visitors

481 profile views

zorphnog's Achievements

Universalist

Universalist (7/7)

11

Reputation

  1. If the key/value in question is in both hives (64-bit and 32-bit), then yes you have to call RegDelete twice. Are you running 64-bit AutoIt or 32-bit? What key/value are you trying to delete?
  2. I'm not sure about doing it through the registry, but you can set it through powercfg commands. The pre-configured schemes have the following GUIDs: Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced) Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c (High performance) Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a (Power saver) I'll use the Balanced scheme for my examples, but you would use the GUID provided by: powercfg -GETACTIVESCHEME You can find the GUIDs for subgroups and power settings as well as the index values for each power setting by running a query command with your scheme GUID: powercfg -Q 381b4222-f694-41f0-9685-ff5bb260df2e Looking through the output, you will discover that the subgroup GUID you want is: Subgroup GUID: 4f971e89-eebd-4455-a8de-9e59040e7347 (Power buttons and lid) and the power setting: Power Setting GUID: 5ca83367-6e45-459f-a27b-476b1d01c936 (Lid close action) with index options: Possible Setting Index: 000 Possible Setting Friendly Name: Do nothing Possible Setting Index: 001 Possible Setting Friendly Name: Sleep Possible Setting Index: 002 Possible Setting Friendly Name: Hibernate Possible Setting Index: 003 Possible Setting Friendly Name: Shut down So in order to configure your system to Shut down when the lid is closed, you would run: powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 3 powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 3 AC for the "Plugged In" action and DC for the "On Battery" action.
  3. I routinely need to log information for my scripts. In the past, I've usually just created functions in each script to write to a log file. I also use ConsoleWrite in conjunction with SciTE a lot when I'm trying to debug scripts. After using some logging libraries for other languages (namely NLog (C#) and Java (log4j)) I decided to write a logging UDF for AutoIt. I decided to base it loosely upon the log4j and NLog libaries. I say loosely because this one is not nearly as feature rich as either one of those, but I think it still provides a nice logging interface. What can it do? Output types: Console, File, or Both. Additionally, you can configure the logger to output differently based on whether the script is compiled or not. This way you can output to the console (SciTE) while you're writing a script, and output to a log file when you've compile the script. Log levels: While I don't think it's really necessary to have this many log levels, these are the levels in ascending order of severity: Trace Debug Info Warn Error Fatal Log Filtering: The log can be enabled and disabled. There are also minimum and maximum log levels that can be configured to only show a range of log levels (i.e. a minimum level of warn would not log messages for trace, debug, or info). These filter levels can be overridden when logging a message if the need be. Error Stream: Logging can be configured to write to the stderr (i.e. ConsoleWriteError). When enabled, any log messages at the error level and above will be written to the error stream. Message Format Macros: The logging message format can be customized to your liking using the following macros: ${date} = Long date (i.e. MM/DD/YYYY HH:MM:SS) ${host} = Hostname of local machine ${level} = The current log level ${message} = The log message ${newline} = Insert a newline ${shortdate} = Short date (i.e. MM/DD/YYYY) Available Functions: Configuration Functions _log4a_SetCompiledOutput - Sets the logging output type for the compiled version of the script (Default: $LOG4A_OUTPUT_FILE) _log4a_SetEnable - Enables or disables logging messages (Default: Disabled) _log4a_SetErrorStream - Enables or disables logging of the standard error stream (Default: Enabled) _log4a_SetFormat - Configures the format of logging messages (Default: "${date} ${level} ${message}") _log4a_SetLogFile - Sets the path of the log file (Default: "<ScriptFullPath>.log") _log4a_SetMaxLevel - Configures the maximum log level to process messages (Default: $LOG4A_LEVEL_FATAL) _log4a_SetMinLevel - Configures the minimum log level to process messages (Default: $LOG4A_LEVEL_TRACE) _log4a_SetOutput - Sets the logging output type for the non-compiled version of the script (Default: $LOG4A_OUTPUT_CONSOLE) Logging Functions _log4a_Debug - Logs a message at the debug level _log4a_Error - Logs a message at the error level _log4a_Fatal - Logs a message at the fatal level _log4a_Info - Logs a message at the info level _log4a_Message - Logs a message to the configured outputs _log4a_Trace - Logs a message at the trace level _log4a_Warn - Logs a message at the warn level See the source file for full documentation of available functions. A quick example script: #include "log4a.au3" ; Enable logging and don't write to stderr _log4a_SetEnable() _log4a_SetErrorStream(False) log_messages() ; Write to stderr, set min level to warn, customize message format _log4a_SetErrorStream() _log4a_SetMinLevel($LOG4A_LEVEL_INFO) If @compiled Then _log4a_SetMinLevel($LOG4A_LEVEL_WARN) ; Change the min level if the script is compiled _log4a_SetFormat("${shortdate} | ${host} | ${level} | ${message}") log_messages() ; Disable logging (except for those that override) _log4a_SetEnable(False) log_messages() Func log_messages() _log4a_Trace("A TRACE message", True) ; overrides filters _log4a_Debug("A DEBUG message") _log4a_Info("A INFO message") _log4a_Warn("A WARN message") _log4a_Error("A ERROR message", True) ; overrides filters _log4a_Fatal("A FATAL message") EndFunc Without further adieu, the UDF: log4a.au3
  4. Hmm...ok. If it works that's great. What is the value of $r in your Case 1 statement though? As far as the case statements, I wish every language would adopt the same convention. Must have had my C/C++ coding hat on.
  5. Try: Dim $bFound = False Switch UBound($data, 0) Case 1: If $data[6] == $var2 Then If FileExists ($xmlFile) Then ; do some stuff MsgBox(4096, "Found", "Found element") $bFound = True Else MsgBox (4096, "Error", "The XML file was not found") EndIf EndIf Case 2: For $r = 1 to Ubound($data) - 1 If $data[$r][6] == $var2 Then If FileExists ($xmlFile) Then ; do some stuff MsgBox(4096, "Found", "Found element") $bFound = True ExitLoop Else MsgBox (4096, "Error", "The XML file was not found") EndIf EndIf Next EndSwitch If Not $bFound Then MsgBox (4096, "Error", "values do not match")
  6. Do you have an example of the html and the text that you want? There are other _IE functions that can return specific elements of the DOM, but without knowing the specifics it is hard to recommend a solution.
  7. What do you mean when you say 'load/read' files? Are you using FileFindFirstFile and FileFindNextFile to find the files based on the filter? We need more information about the implementation of your 'load/read' (actual code would be even better).
  8. You can certainly write these functions in a separate file (and probably should since you are reusing code). In the case of the combo box example, you would just need to pass a handle of the combo to the function.
  9. Next time I would suggest adding the code to the post in code blocks as opposed to attaching it. Here's an alternate implmentation: Local $aDrives, $iHomeDrive, $iFolderDrive = 0, $sMsg = "" $aDrives = DriveGetDrive("FIXED") If @error Then MsgBox(0, "Error", "Could not get drive information.") Exit EndIf Dim $aDriveInfo[$aDrives[0] + 1][2] $aDriveInfo[0][0] = $aDrives[0] For $i=1 to $aDrives[0] $aDriveInfo[$i][0] = StringUpper($aDrives[$i]) $aDriveInfo[$i][1] = DriveSpaceFree($aDrives[$i] & "") If $aDriveInfo[$i][0] = @HomeDrive Then $iHomeDriveFreeSpace = $aDriveInfo[$i][1] $iHomeDrive = $i Else If $iFolderDrive == 0 And $aDriveInfo[$i][1] >= 1024 Then $iFolderDrive = $i EndIf $sMsg &= StringFormat("%s (%.2f MB)n", $aDriveInfo[$i][0], $aDriveInfo[$i][1]) Next MsgBox(0, "", $sMsg) If $aDriveInfo[$iHomeDrive][1] < 1024 Then MsgBox(0,"Cannot Install","Not enough space or Operating System on wrong Drive"&@OSVersion&@OSArch) Exit ElseIf $iFolderDrive == 0 And $aDriveInfo[$iHomeDrive][1] < 2048 Then MsgBox(0,"Cannot Install","Not enough space for folders"&@OSVersion&@OSArch) Exit Else $sMsg = "" If $iFolderDrive == 0 Then $iFolderDrive = $iHomeDrive Switch @OSVersion Case "WIN_7" Switch @OSArch Case "X86" $sMsg = StringFormat("Installing 32 bit Software to Drive %s and Folders to Drive %s [%s %s]", _ $aDriveInfo[$iHomeDrive][0], $aDriveInfo[$iFolderDrive][0], @OSVersion, @OSArch) Case "IA64", "X64" $sMsg = StringFormat("Installing 64 bit Software to Drive %s and Folders to Drive %s [%s %s]", _ $aDriveInfo[$iHomeDrive][0], $aDriveInfo[$iFolderDrive][0], @OSVersion, @OSArch) EndSwitch MsgBox(0, "", $sMsg) Case "WIN_XP" ; same thing EndSwitch EndIf
  10. I understand what you are trying to do by looping through the data, the part I was referring to is that in your original post you have $data[$][6] instead of $data[$r][6]. This is a syntax error. The logic is sound. I think I just misunderstood your question. I think you basically want one of two results: a message of that the item was found or a message that none of the rows in the data array matched. In that case you need to handle the 'no match' case outside of the for loop: Dim $bFound = False For $r = 1 to Ubound($data) -1 If $data[$][6] == $var2 Then If FileExists ($xmlFile) Then ; do some stuff MsgBox(4096, "Found", "Found element") $bFound = True ExitLoop Else MsgBox (4096, "Error", "The XML file was not found") EndIf EndIf Next If Not $bFound Then MsgBox (4096, "Error", "values do not match")
  11. Not sure if this is a typo in the post or in your code, but $ is not a valid index. Did you intend to use $r? If $data[$r][6] == $var2 Then
  12. Well I'm not familiar with SCOM so I'm not sure how it invokes a process and I'm not sure of all the specifics of your intended solution. If you are having problems with the being able to "see" windows through your script, one solution might be to run the script as a startup script for users and have it store the time results in the registry or text file. Then have your SCOM script simply read that file/registry value for reporting. Another question would be whether the Run/ShellExecute function is actually spawning anything. You could check for the existence of the process: While TimerDiff($ts) < 60000 If ProcessExists("yourprocess.exe") Then ConsoleWrite(1) Exit EndIf Sleep(250) WEnd ConsoleWrite(0)
  13. There are several WMI classes you can use with Remote Desktop Connection Broker (Terminal Services Session Broker) if that is what your load balancing server is. Perhaps using WMI and the Win32_SessionDirectorySession on the load balancing server? One caveat to querying a session though. Something like: Dim $objWMIService, $oSessions $objWMIService = ObjGet("winmgmts:.rootcimv2") If @error Then MsgBox(4096, "RDP Session", "ERROR - Could not get WMIService.") Exit(1) EndIf $oSessions = $objWMIService.ExecQuery("SELECT * FROM Win32_SessionDirectorySession WHERE UserName='<UserName>' AND DomainName='<DomainName>'") If IsObj($oSessions) Then For $oSessItem In $oSessions $sMsg = StringFormat("ServerIPAddress: %snServerName: %snSessionID: %snSessionState: %sn", _ $oSessItem.ServerIPAddress, $oSessItem.ServerName, $oSessItem.SessionID, $oSessItem.SessionState) MsgBox(4096, "RDP Session", $sMsg) Next Else MsgBox(4096, "RDP Session", "ERROR - Session query execution failed.") EndIf $oSessions = 0 $objWMIService = 0
  14. As @abberration said, use a direct call to executable or if you want to use the shortcut then use ShellExecute: ShellExecute("C:UsersomagentAppDataRoamingMicrosoftWindowsStart MenuProgramsPRD SCM 55Sunrise Clinical Manager.lnk") Also, not sure what's going on with the whole .bat file solution for ConsoleWrite, just use (it's much cleaner): #AutoIt3Wrapper_Change2CUI=y Lastly, this could all be done in just an AutoIt script to begin with: Local $iInit, $iDiff = 60000 $iInit = TimerInit() ShellExecute('C:UsersomagentAppDataRoamingMicrosoftWindowsStart MenuProgramsPRD SCM 55Sunrise Clinical Manager.lnk') If WinWait( "Allscripts Gateway Logon","", 60 ) Then $iDiff = TimerDiff($iInit) WinClose( "Allscripts Gateway Logon" ) EndIf ConsoleWrite(StringFormat("%#.6g", $iDiff)) $oAPI = ObjCreate("MOM.ScriptAPI") $oBag = $oAPI.CreatePropertyBag() $oBag.AddValue("Time", $iDiff) $oAPI.Return($oBag) $oAPI.LogScriptEvent("Citrix SCM Startup Time =", 111, 0, $iDiff)
  15. You should be able to retrieve the hostname from the window title. $$sComputer = _GetRemoteConnectionTitle() MsgBox(4096, "Remote Computer Name", $sComputer) Func _GetRemoteConnectionTitle() $sTitle = WinGetTitle("[CLASS:TscShellContainerClass]") $aResult = StringRegExp($sTitle, "(?i)(.+)s-sremote desktop connection", 3) If @error Then Return SetError(1, 0, "") Return $aResult[0] EndFunc
×
×
  • Create New...