Jump to content

Recommended Posts

Posted

Hi all.

I have spent all day on a screen saver that has been great for practice. Now I am looking for a way to create a .scr file to put into the system32 directory.

Heres my problem. I compile the test script into the directory to a .scr file. Problem is, no matter what I do, I cannot get it to do anything but skip right over the code. Even when I click configure.

Heres my code:

If UBound($CmdLine) > 1 Then
$Command = StringLeft($CmdLine[1], 2)
If $Command == "/c" Then
$mode = 0
ElseIf $Command == "/s" Then
$mode = 1
ElseIf $Command == "/p" Then
$mode = 2
Else
If @Compiled Then $mode = 0
EndIf
 
EndIf

Switch $mode ;0 - config, 1 - run, 2 - preview
    Case 0
        Run("config.exe")
    Case 1
        Run("Screen saver execute.exe")
EndSwitch

The worst part of it is, I have searched all over the forum and help file for examples for command line scripts that I can actually understand. I havent found any so far.

If somone could help me correct the code, that would be great.

Thanks everyone!!! :)

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Posted (edited)

I think the prob is your If statements. Try this.

If UBound($CmdLine) > 1 Then
    $Command = StringLeft($CmdLine[1], 2)
    If $Command == "/c" Then
        $mode = 0
    ElseIf $Command == "/s" Then
        $mode = 1
    ElseIf $Command == "/p" Then
        $mode = 2
    EndIf
EndIf
Edited by spudw2k
Posted

When I tried to run it, I got this error:

---------------------------

AutoIt Error

---------------------------

Line 18 (File "C:\Users\draygoes\Desktop\Knight47 Wallpaper Screen saver\Knight47 Wallpaper ScreenSaver Advanced.au3"):

EndIf

Error: "EndIf" statement with no matching "If" statement.

---------------------------

OK

---------------------------

I am sorry this is takeing so long.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Posted

You prob have another bad if statement somewhere. If you wanna share the code provately, I'll be happy to look at it. What is before and upto Line 18?

Posted

I am completely lost. Could you please clean up this code so that it will work, then explain to me how you did it?

Thanks everyone.

This is the complete source code:

If UBound($CmdLine) > 1 Then
    $Command = StringLeft($CmdLine[1], 2)
    If $Command == "/c" Then
        $mode = 0
    ElseIf $Command == "/s" Then
        $mode = 1
    ElseIf $Command == "/p" Then
        $mode = 2
    EndIf

Switch $mode ;0 - config, 1 - run, 2 - preview
    Case 0
        Run("config.exe")
    Case 1
        Run("Screen saver execute.exe")
EndSwitch
Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Posted

Sorry to bump, but the topic seems to have gone over to the seconed page.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Posted (edited)

@draygoes..Try this...

#include <Array.au3>

;From the Help File...
;$CmdLine[0] is number of parameters
;$CmdLine[1] is param 1 (after the script name)
;$CmdLine[2] is param 2 etc

;For example you run some program with /s parameter....(Great.exe /s)
;To see what the hell are the values...display the array...if you get no values for the second element then you are passing the parameters incorrectly.
;_ArrayDisplay($CmdLine,"Check")


If $CmdLine[0] = 0 then 
    MsgBox(4096+48, "Oops...", "No Parameter Found, Please Try Again.")
Exit
Else

Select
    
    Case $CmdLine[1] = "/c"
    $mode=0

    Case $CmdLine[1] = "/s"
    $mode=1
    
    Case $CmdLine[1] = "/p"
    $mode=2
    
    Case Else;You need to use the case else because if you dont pass the parameters /c, /s, /p it needs to do something.
    $mode=-1

EndSelect



Switch $mode;0 - config, 1 - run, 2 - preview
    Case 0
        Run("config.exe")
    Case 1
        Run("Screen saver execute.exe")
EndSwitch

EndIf
Edited by DjDeep00
Posted (edited)

Yay!!! I finally understand command line perameters!!! Thanks friend.

Ok, now I have another problem. I have edited the script for testing so that it will display msgbox's insted of running files, so that I could test to see if this was correct.

Eather I havr the wrong ideas, the script is incorrect, or windows is passing the script with no parimeters at all.

Heres my edited code:

#include <Array.au3>

;From the Help File...
;$CmdLine[0] is number of parameters
;$CmdLine[1] is param 1 (after the script name)
;$CmdLine[2] is param 2 etc

;For example you run some program with /s parameter....(Great.exe /s)
;To see what the hell are the values...display the array...if you get no values for the second element then you are passing the parameters incorrectly.
;_ArrayDisplay($CmdLine,"Check")


If $CmdLine[0] = 0 then
    MsgBox(0,"","None")
Exit

Else

Select
    
    Case $CmdLine[1] = "/c"
    $mode=0
    Case $CmdLine[1] = "-c"
    $mode=0
    Case $CmdLine[1] = "c"
    $mode=0
    
    Case $CmdLine[1] = "/s"
    $mode=1
    
    Case $CmdLine[1] = "-s"
    $mode=1
    
    Case $CmdLine[1] = "s"
    $mode=1
    
    Case $CmdLine[1] = "/p"
    $mode=2
    Case $CmdLine[1] = "-p"
    $mode=2
    Case $CmdLine[1] = "p"
    $mode=2
    
    Case Else;You need to use the case else because if you dont pass the parameters /c, /s, /p it needs to do something.
    $mode=-1

EndSelect



Switch $mode;0 - config, 1 - run, 2 - preview
    Case 0
      MsgBox(0,"","Configure")
    Case 1
      msgbox(0,"","Run")
  Case 2
      MsgBox(0, "", "Preview")
EndSwitch

EndIf

To see what I mean, compile the script with a .scr extention and rightclick the file, click configure. No matter what you click, you will allways get none.

Edited by draygoes
Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Posted

I am sorry, but it didnt work.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Posted

Yay!!! I finally understand command line perameters!!! Thanks friend.

Ok, now I have another problem. I have edited the script for testing so that it will display msgbox's insted of running files, so that I could test to see if this was correct.

Eather I havr the wrong ideas, the script is incorrect, or windows is passing the script with no parimeters at all.

To see what I mean, compile the script with a .scr extention and rightclick the file, click configure. No matter what you click, you will allways get none.

I guess Right Click -> Configure doesn't throw any params. Since -c is the default action anyways for an scr (even when no params are used) you could just do this.

If $CMDLINE[0] = "" Then $mode=0

Also, just a recommendation, you can simplify the whole -c versus /c by using StringInstr()

If StringInstr($CmdLine[1],"c") > 0 Then
    $mode=0
ElseIf StringInstr($CmdLine[1],"s") > 0 Then
    $mode=1
ElseIf StringInstr($CmdLine[1],"p") > 0 Then
    $mode=2
EndIf

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
×
×
  • Create New...