Jump to content

robinj

Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by robinj

  1. I have some JSON in a variable that is totally unformatted as returned from a REST API call. What is the best way to extract the values from it using this UDF. It should be simple, but struggling to get it working as it should Example JSON [{"id":"4434156","url":"https://legacy.sky.com/v2/schedules/4434156","title":"468_CORE_1_R.4 Schedule","time_zone":"London","start_at":"2017/08/10 19:00:00 +0100","end_at":null,"notify_user":false,"delete_at_end":false,"executions":[],"recurring_days":[],"actions":[{"type":"run","offset":0}],"next_action_name":"run","next_action_time":"2017/08/10 14:00:00 -0400","user":{"id":"9604","url":"https://legacy.sky.com/v2/users/9604","login_name":"robin@ltree.com","first_name":"Robin","last_name":"John","email":"robin@ltree.com","role":"admin","deleted":false},"region":"EMEA","can_edit":true,"vm_ids":null,"configuration_id":"19019196","configuration_url":"https://legacy.sky.com/v2/configurations/19019196","configuration_name":"468_CORE_1_R.4"},{"id":"4444568","url":"https://legacy.sky.com/v2/schedules/4444568","title":"468_CORE_1_R.4 Schedule","time_zone":"London","start_at":"2017/08/11 12:00:00 +0100","end_at":null,"notify_user":false,"delete_at_end":false,"executions":[],"recurring_days":[],"actions":[{"type":"suspend","offset":0}],"next_action_name":"suspend","next_action_time":"2017/08/11 07:00:00 -0400","user":{"id":"9604","url":"https://legacy.sky.com/v2/users/9604","login_name":"robin@ltree.com","first_name":"Robin","last_name":"John","email":"robin@ltree.com","role":"admin","deleted":false},"region":"EMEA","can_edit":true,"vm_ids":null,"configuration_id":"19019196","configuration_url":"https://legacy.sky.com/v2/configurations/19019196","configuration_name":"468_CORE_1_R.4"}] Thanks for any help
  2. I was looking for a solution to this issue today in the forums and could not find anything that seemed to do the job required. IE. to return the exit errorlevel of an external command that was forked using the 'Run' command once it completes. I pulled a couple of functions from some other code I had that I probably aquired from someone else, but posting here because they do work ;Run your program $PID = Run("MYPROGRAM.EXE") ;Retrieve the real windows process ID $SYSTEMPID = _ProcessGetHandle($VAR) ;Do your code in the meantime until MYPROGRAM terminates While ProcessExists($PID) Sleep(500) WEnd ;When it's complete, retrieve the errorlevel $ERRORLEVEL = _ProcessGetExitCode($SYSTEMPID) ;Display it MsgBox($MB_SYSTEMMODAL, "Exit ERRORLEVEL is ", $ERRORLEVEL) Exit ; Return handle of given PID Func _ProcessGetHandle($iPID) Local Const $PROCESS_QUERY_INFORMATION = 0x0400 Local $avRET = DllCall("kernel32.dll", "ptr", "OpenProcess", "int", $PROCESS_QUERY_INFORMATION, "int", 0, "int", $iPID) If @error Then Return SetError(1, 0, 0) Else Return $avRET[0] EndIf EndFunc ;==>_ProcessGetHandle ; Get process exit code from handle Func _ProcessGetExitCode($hProc) Local $t_ExitCode = DllStructCreate("int") Local $avRET = DllCall("kernel32.dll", "int", "GetExitCodeProcess", "ptr", $hProc, "ptr", DllStructGetPtr($t_ExitCode)) If @error Then Return SetError(1, 0, 0) Else Return DllStructGetData($t_ExitCode, 1) EndIf EndFunc ;==>_ProcessGetExitCode
  3. I noticed a lot of people talking about how to set your IP address, but no one seems to have had a stab at how to do it using NetSH. Here is a function that I wrote which seems to do it. It could be improved and provide feedback etc, but I just needed somthing quick to replace a broken registry slam system I used previously. This grabs a list of NICs, then verifies if on PCI bus and hence a real one, not tunnel or loopback etc (you may wish to switch PCI for USB). If real, then it grabs interface name and then uses NetSH to set IP Address, Subnet, Gateway and up to 3 DNS servers. Leave the $myip field blank or set to dhcp if you wish DHCP instead of a STATIC IP #RequireAdmin #include <Constants.au3> ;Developed by Robin Johnston May 2015 ;To test, comment out or delete the ones you don't want ;IP & GW only SetIPAddress("10.1.1.1", "255.255.0.0", "10.1.1.254", "") ;IP, GW & 2 DNS SetIPAddress("10.1.1.1", "255.255.0.0", "10.1.1.254", "10.1.1.253, 8.8.8.8") ;DHCP SetIPAddress("dhcp", "", "", "") ;OR SetIPAddress("", "", "", "") ;OR SetIPAddress() Exit Func SetIPAddress($myip="",$mysub="",$mygate="",$mydns="") ;Updated May 2015 to set just the primary PCI NIC using NetSH ;Get list of active connections - can't use runwait here Local $pid = Run(@ComSpec & " /c netsh.exe int show int", "", @SW_HIDE, $STDOUT_CHILD) ;Wait until the process has closed using the PID returned by Run. ProcessWaitClose($pid) ;Read the Stdout stream of the PID returned by Run Local $output = StdoutRead($pid) ;Use StringSplit to split the output of StdoutRead to an array. All carriage returns (@CRLF) are stripped and @CRLF (line feed) is used as the delimiter. Local $lans = StringSplit(StringTrimRight(StringStripCR($output), StringLen(@CRLF)), @CRLF) ;Loop through array looking for 'dedicated' connections For $i = 1 to UBound($lans)-1 Step 1 If StringInStr($lans[$i],"Dedicated") Then ;A valid connection so lets check it out - strip out connection ID $pos=StringInStr($lans[$i]," ",0,-1) $conn=StringTrimLeft($lans[$i],$pos+1) ;Use WMIC to verify connection goes to a real adapter $pid = Run(@ComSpec & ' /c wmic.exe nic where(NetConnectionID="'& $conn &'") get PNPDeviceID', "", @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($pid) $output = StdoutRead($pid) $device=StringSplit(StringTrimRight(StringStripCR($output), StringLen(@CRLF)), @CRLF)[2] ;Valid devices types can be PCI for onboard/internal NICs, USB for plugin USB NICs and ROOT for software based adapters such as tunnels or loopback NICs If StringInStr($device,"PCI\") Then ConsoleWrite("Connection '" & $conn & "' on device " & $device & " is being set..." & @CR) If StringInStr($myip,"dhcp") Or $myip="" Then RunWait(@ComSpec & ' /c netsh.exe int ip set address "' & $conn & '" dhcp',"", @SW_HIDE) RunWait(@ComSpec & ' /c netsh.exe int ip set dns "' & $conn & '" dhcp', "", @SW_HIDE) ConsoleWrite("-Setting DHCP IP & DNS" & @CR) Else RunWait(@ComSpec & ' /c netsh.exe int ip set address "' & $conn & '" static ' & $myip & ' ' & $mysub & ' ' & $mygate & ' 1', "", @SW_HIDE) ConsoleWrite("-Setting IP Addr" & @CR) Local $dns=StringSplit($mydns,",") If UBound($dns)>1 And $dns[1]<>"" Then ConsoleWrite("-Setting DNS1" & @CR) RunWait(@ComSpec & ' /c netsh.exe int ip set dns name="' & $conn & '" static ' & $dns[1] & ' validate=no', "", @SW_HIDE) If UBound($dns)>2 And $dns[2]<>"" Then ConsoleWrite("-Setting DNS2" & @CR) RunWait(@ComSpec & ' /c netsh.exe int ip add dns name="' & $conn & '" ' & $dns[2] & ' index=2 validate=no', "", @SW_HIDE) If UBound($dns)>3 And $dns[3]<>"" Then ConsoleWrite("-Setting DNS3" & @CR) RunWait(@ComSpec & ' /c netsh.exe int ip add dns name="' & $conn & '" ' & $dns[3] & ' index=3', "", @SW_HIDE) EndIf EndIf EndIf EndIf EndIf EndIf Next EndFunc ;SetIPAddress
  4. Hello Yashied, Just wanted to say that this is a very slick piece of software. Have learnt a lot from checking through your source code. One small request if you are doing any further work on it would be to add support for UK keyboard. I know it works in terms of switching, but gives same display (US Flag & English) as it does for US keyboard layout and those are the two that I am always switching between! Great tool Robin
  5. Just taking a look at your code because I want a service I am writing to pop up a status message on screen with option to abort. I take it that your code has two components, one running in system account and one under the user account? not able to access you code since zip file is password protected.... Robin
  6. Obviously, this will work, but is there no simple way to change the system font/styles.....?
  7. I am trying to create a script where I have several message boxes that display on some very high resolution monitors and would love to use Msgbox function to display script status etc. Issue I have is the font is too small. Is there any simple way to change it for functions such as msgbox? I can't easily locate an answer to this. Thanks
  8. Was just trying to source the VNC Plugin. Any available links. Ones in the post all seem dead now.... Thanks
×
×
  • Create New...