Jump to content

Command Line Switches[SOLVED]


Recommended Posts

Hey everyone one I'm using the following at the start of my script to make sure the script itself is being run using domain admin rights:

MsgBox (0, "", "test")
If $cmdline[0] > 0 Then
    If String($cmdline[1]) = "/s" Then
        $sUserName = InputBox ("User", "Enter username to unlock:")
    Else
        MsgBox (16, "Error", "Unknown command, exiting.")
        Exit
    EndIf
Else
    $sPass = InputBox ("Password", "Please enter the administrator password:", "", "*")
    $sPID = RunAs ("administrator", "domain", $sPass, 0, "control.exe inetcpl.cpl", "", @SW_HIDE)
    If $sPID = 0 Then
        MsgBox (16, "Error", "Password incorrect, exiting.")
        Exit
    EndIf
    ProcessClose ($sPID)
    RunAs ("administrator", "domain", $sPass, 2, "network_path\unlockacct.exe /s")
    Exit
EndIf

The problem I'm having is that when it restarts it appears to skip the beginning and goes right back to the else statement. I haven't had to use the command line switches for awhile but if i remember right isn't $cmdline always an array and $cmdline[0] contains number of switches? Maybe I'm just taking an odd ball approach to this but any help will be appreciated. Thank you in advance.

Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Thank you for your help. If you look at the RunAs () statement I have the /s switch at the end of the path. I thought I remembered doing it this way before but if I'm wrong please let me know.

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

I tried that too...the first run I get a 0 (expected value) on the restart i get no msgbox at all...this is where im confused.

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

LurchMan,

I tend to handle command line arguments like so.

For $i = 1 To $CMDLine[0]
    Switch StringUpper($CMDLine[$i])
        Case "PARAM1"
            MsgBox(0, "", "You called param 1")
        Case "PARAM2"
            Beep(200)
            MsgBox(0, "", "I beeped :P")
        Case "PARAM3"
            Beep(500)
            Beep(1000)
            MsgBox(0, ":O", "I made noises!")
    EndSwitch
Next

This is only a basic example. It allows for users to call the same argument over and over which can be good, but most applications don't require it.

James

Link to comment
Share on other sites

Paulie - I'm trying to avoid right clicking --> Run As

James - Isn't that kind of over complicating it when there will only be 1 parm?

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

Thank you for your help guys...I feel like an idiot now that I know why it wasn't working...it usually helps to recompile the source when it calls the exe....

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...