Jump to content
Sign in to follow this  
sublimnl

Script exits immediately in SciTE

Recommended Posts

sublimnl

Can anyone say why this script exits immediately in SciTE?  Its strange, SciTE reports that the script has finished even though its still running in the background.  As a result, I am not getting output written to the SciTE console and my for loop at line 20 is only executed once.  SciTE actually reports that the script has finished executing before my test MsgBox on line 11! 

Here's the code:

#include <File.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#RequireAdmin

MsgBox(4096,"","test")

Global $servers[1]
Global $arrMA[1]
$CommServes = "cs1,cs2"
$CommServes = StringSplit($CommServes,",")
$CommServes = _ArrayUnique($CommServes,1,1)
_ArrayDelete($CommServes,0)

$strPassword = InputBox("Enter Password","Enter Password for user","","•",200,135)

For $cs in $CommServes
    CSConnect()
Next

Exit



Func CSConnect()

ConsoleWrite(@CRLF & "Connecting to " & $cs)
    RunWait(@ComSpec & " /c qlogin -cs " & $cs & " -csn " & $cs & " -u admin -clp " & $strPassword & "|clip", @WindowsDir, @SW_HIDE, $STDOUT_CHILD)
    $result = ClipGet()
    ConsoleWrite(@CRLF & ClipGet())
    If StringInStr($result,"Error") > 0 Then
        MsgBox(4096,"Logon Error","Error during logon attempt.  Exiting" & @CRLF & @CRLF & $result)
        Exit
    Else
        RunWait(@ComSpec & " /c qlist mediaagent -cs " & $cs & "|clip", @WindowsDir, @SW_HIDE, $STDOUT_CHILD)
        $qlist = ClipGet()
        $qlist = StringStripWS(StringReplace($qlist,@CRLF,","),$STR_STRIPALL)
        If StringRight($qlist,1) = "," Then $qlist = StringTrimRight($qlist,1)
        $qlist = StringSplit($qlist,",")
        _ArrayDelete($qlist,0)
        _ArraySort($qlist)
        _ArrayUnique($qlist)
        $qlist = _ArrayToString($qlist,",")
        ScanThem($qlist)
        ConsoleWrite(@CRLF & "Disconnecting from " & $cs)
        RunWait(@ComSpec & " /c qlogout -cs " & $cs & "|clip", @WindowsDir, @SW_HIDE, $STDOUT_CHILD)
        ConsoleWrite(@CRLF & ClipGet())
    EndIf

EndFunc



Func ScanThem($ma)
    $strComputer = $ma
    $PS = Run("powershell.exe get-wmiobject -computer " & $strComputer & " win32_volume | where-object {$_.driveletter -eq $null -and $_.caption -NotLike '\\?\Volume*'} | select ""@{Name='Date';Expression={$((Get-Date).ToString('MM-dd-yyyy'))}},@{Name='Media Agent';Expression={$_.systemname}},@{Name='Mount Path';Expression={$_.Caption}},@{Name='Capacity (GB)';expression={[math]::round(($_.Capacity/ 1073741824),2)}},@{Name='FreeSpace (GB)';expression={[math]::round(($_.FreeSpace/ 1073741824),2)}}""|Export-CSV C:\export.csv -notype -append",@SystemDir, @SW_HIDE, $STDOUT_CHILD)
    ProcessWaitClose($PS)
    $result = StdoutRead($PS)
    ConsoleWrite($result)
EndFunc

Share this post


Link to post
Share on other sites
FireFox

The #RequireAdmin function forces the script to run as administrator.

Since your SciTE is not run as admin it can't execute your script with admin privileges, so it won't be the owner of your process.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
sublimnl

Thanks guys.  That was correct.  I am not sure what happened, but I had the same SciTE process open all weekend and suddenly it started doing that this morning (between edits actually) despite the fact that #RequireAdmin was there all along. Sure enough, re-launching SciTE as an elevated process got it working once again.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×