Deon Posted September 30, 2014 Posted September 30, 2014 I'm using the below code from an >old forum post, but I logon to my computer as a standard user, and I'll need to connect to the other computer as an Administrator (with a different username). I can use RunAs for now, but I'd like a way to hard-code my credentials into the script (yes, I'm aware others can decompile it - no one else will be using the script), so I don't have to use RunAs everytime. Here's the code at the moment: expandcollapse popup#AutoIt3Wrapper_Change2CUI=Y #include <Date.au3> $strComputer = InputBox("Remote Uptime","What's the DNS?") If $cmdline[0] Then If StringInstr($cmdlineraw,"?") Then MsgBox(0,"Remote Uptime",@CRLF & "Description:" & @CRLF & @TAB & "Displays system up time for local or remote machines." & @CRLF) MsgBox(0,"Remote Uptime",@CRLF & "Parameter List:" & @CRLF & @TAB & "/?" & @TAB & @TAB & @TAB & "Displays this help/usage." & @CRLF) MsgBox(0,"Remote Uptime",@CRLF & "Examples:" & @CRLF & @TAB & @ScriptName & @CRLF) MsgBox(0,"Remote Uptime",@TAB & @ScriptName & " hostname1 hostname2 hostname3" & @CRLF) Exit EndIf For $x = 1 To $cmdline[0] MsgBox(0,"Remote Uptime",StringUpper($cmdline[$x]) & " " & _Uptime($cmdline[$x])&@CRLF) Next Else MsgBox(0,"Remote Uptime",_Uptime($strComputer) & @CRLF) EndIf Func _Uptime($strComputer) $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") If Not IsObj($objWMIService) Then Return "Failed to connect... sorry about that." $colOperatingSystems = $objWMIService.ExecQuery("Select LastBootUpTime from Win32_OperatingSystem") For $objOS in $colOperatingSystems $dtmBootup = $objOS.LastBootUpTime $dtmLastBootupTime = _WMIDateStringToDate($dtmBootup) Next Return _FormatUptime($dtmLastBootupTime) EndFunc Func _WMIDateStringToDate($dtmBootup) Return StringLeft($dtmBootup,4) & "/" & StringMid($dtmBootup, 5, 2) & "/" & StringMid($dtmBootup, 7, 2) & " " & StringMid($dtmBootup, 9, 2) & ":" & StringMid($dtmBootup, 11, 2) & ":" & StringMid($dtmBootup, 13, 2) EndFunc Func _FormatUptime($dtmLastBootupTime) Dim $arrdatediffs[4][3]=[[0,24," day"],[0,60," hour"],[0,60," minute"],[0,1," second"]] $datediff = StringSplit("D|h|n|s","|") $tNow = _NowCalc() For $diff = 1 to $datediff[0] $arrdatediffs[$diff-1][0] = _DateDiff($datediff[$diff], $dtmLastBootUpTime, $tNow) Next $ubound = UBound($arrdatediffs)-1 For $x = $ubound To 0 Step -1 If $x > 0 Then If $arrdatediffs[$x-1][0] > 0 Then $arrdatediffs[$x][0] = ($arrdatediffs[$x][0]-($arrdatediffs[$x-1][0]*$arrdatediffs[$x-1][1])) EndIf Next $strUptime = "" For $x = 0 To $ubound If $arrdatediffs[$x][0] > 0 Then $strUptime &= $arrdatediffs[$x][0] & $arrdatediffs[$x][2] If $arrdatediffs[$x][0] > 1 Then $strUptime &= "s" If $x < $ubound Then $strUptime &= ", " EndIf Next Return $strUptime EndFunc
Radiance Posted September 30, 2014 Posted September 30, 2014 Hey, maybe something like this: $User = "" $Pass = "" If $CmdLine[0] = 0 Then RunAs($User, "domain", $Pass, flag, @ScriptFullPath & " -switchuser") Exit EndIf If $CmdLine[1] <> "-switchuser" Then Exit ; Rest of script
UEZ Posted September 30, 2014 Posted September 30, 2014 Can you try this and provide some feedback whether it works? -> Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
spudw2k Posted October 1, 2014 Posted October 1, 2014 @UEZ Is there a particular reason you used SystemUpTime from the Win32_PerfFormattedData_PerfOS_System class? I used LastBootUpTime from the Win32_OperatingSystem class in my script and I don't recall it being susceptible to the sleep issue. I'm just curious. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
UEZ Posted October 1, 2014 Posted October 1, 2014 (edited) spudw2k, there was no particular reason why I used SystemUpTime from the Win32_PerfFormattedData_PerfOS_System class. As far as I can remember this was the WMI class which I found first. I will change it to LastBootUpTime, too when the result is more accurate. Thanks for the hint! Btw, did you test my script whether the login credential code works properly? I've not the environment to test it anymore. Br, UEZ Edited October 1, 2014 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
spudw2k Posted October 1, 2014 Posted October 1, 2014 Btw, did you test my script whether the login credential code works properly? I've not the environment to test it anymore. Br, UEZ Nor do I. Hopefully the OP gets an opportunity to test it. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
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