You are here

Call user defined (batch) scripts during startup and shutdown

11 posts / 0 new
Last post
schentuu
Offline
Last seen: 13 years 4 months ago
Joined: 2010-12-15 07:36
Call user defined (batch) scripts during startup and shutdown

Hello!

Would it be a big deal to call user-defined scripts during startup and closing portableapps.com?

I'm thinking about looking if a specified batch file (for example startup.bat or shutdown.bat) exists in the Data folder.
If it doesn't exist, skip this point.
If it exists, execute the batch file before going on as usual.

Thils will give the user a possibility to define whatever he wants to do during startup or shutdown of portableapps.com without bothering you with "i need this new feature!!".

I think batch will be the best solution because every windows can handle them without requirements. And if the user wishes to use another scriptlanguage (like python or even java) he will be able to write a call of his programm with the corect parameters (like the path to a portable python interpreter) into a batchfile.

This would also cover the request Global Environment Variable Possible? in this forum because Enviroment Variables could be set and unset with batch scripts, too.

solanus
solanus's picture
Offline
Last seen: 9 years 9 months ago
Joined: 2006-01-21 19:12
During startup is easy

You can set up batch files in PortableApps format by simply using the correct file format and appinfo.ini file.
Once it appears in the menu, you can set it to Start Automatically when the menu starts.

I made this half-pony, half-monkey monster to please you.

schentuu
Offline
Last seen: 13 years 4 months ago
Joined: 2010-12-15 07:36
yes, but whats about during shutdown?

You're right, but i can't define a script that is called during the shutdown of portableapps.com.

So when i -for example- connect network share to a free drive letter (with "net use", usefull if you use portableapps a lot within one big network) using my startup-script, then i also want to disconnect the drive when i close my portable apps.
When i define Global system Variables with my script a also want to remove them from the system before leaving.
And so on...

So i got the idea to define two batch-scripts in the portableapps.com/Data/ folder that were called if they exist.

A batchfile for startup wouldn't be nessesary if you want to use the way you described, but it would be much easier to handle when the startup.bat is located in the same directory then the shutdown.bat.
And because of they would be an interface for miscellaneous plugins, they should be located in the /Data/ folder both.

VIItweaker
Offline
Last seen: 1 year 4 months ago
Joined: 2011-02-20 22:32
...

...

Chris Morgan
Chris Morgan's picture
Offline
Last seen: 9 years 1 month ago
Joined: 2007-04-15 21:08
!!?

I'm afraid it's quite clear that you don't know much about how batch scripts work - or know too well and delight in using an extremely messy way of doing it.

  1. Option A

    echo @echo off> volume.bat
    echo SET USB=%cd:~0,2%>> volume.bat
    dir | find "Volume"> go.bat
    call go
    if exist volume.bat del volume.bat
    if exist go.bat del go.bat

    ...!? This takes a lot of thought to work out what it's doing. (And I am utterly bamboozled as to why you'd do it this way - putting "set usb=X:" into volume.bat, lines which will trigger volume.bat with meaningless arguments in go.bat and then calling go.bat and then deleting them...) Just do this:

    @set usb=%cd:~0,2%
    

    Incidentally, %cd:~0,2% is suboptimal; if the working directory is a different drive it won't work. You should use %~d0 instead (%0 being the script path, and the ~d making it take just the drive letter part - X:).

  2. All you're saying here is to create a value in HKEY_CURRENT_USER\Environment...

Please try to just say what you want to say as briefly as reasonably possible, and if you have code, put it in a single contiguous block.

I am a Christian and a developer and moderator here.

“A soft answer turns away wrath, but a harsh word stirs up anger.” – Proverbs 15:1

VIItweaker
Offline
Last seen: 1 year 4 months ago
Joined: 2011-02-20 22:32
...

...

Chris Morgan
Chris Morgan's picture
Offline
Last seen: 9 years 1 month ago
Joined: 2007-04-15 21:08
You still don't understand

The way I posted it helps others be able to see what they are doing.

The scripts that are created can be viewed by placing pauses in between each line as I posted.

Your method works but nobody can see what it does or if it is working.

Sorry, but you're still clearly not understanding. SET USB=%cd:~0,2% is the only line which does anything, the rest is noise which makes it very difficult to understand. It's the only step that does anything - you don't want the rest.

As for %~d0, it does work, but only inside a batch file. It will not work directly from Command Prompt. I think you don't understand the concept of working directory properly; consider something like this from the console; echo_d0.bat has the contents @echo %~d0 and echo_cd.bat has the contents @echo %cd:~0,2%:

X:\>echo_d0.bat
X:

X:\>echo_cd.bat
X:

X:\>cd /d C:\Documents and Settings\chrism

C:\Documents and Settings\chrism>X:\echo_d0.bat
X:

C:\Documents and Settings\chrism>X:\echo_cd.bat
C:

The point with the last example is that %cd% is C:\Documents and Settings\chrism, whereas %0 would be X:\cd.bat and so %~d0 X:. Thus it's more stable.

I am a Christian and a developer and moderator here.

“A soft answer turns away wrath, but a harsh word stirs up anger.” – Proverbs 15:1

VIItweaker
Offline
Last seen: 1 year 4 months ago
Joined: 2011-02-20 22:32
...

...

Ph4n70m
Ph4n70m's picture
Offline
Last seen: 2 years 1 month ago
Joined: 2007-01-12 19:22
.

Create a .cmd or .bat file and add this:

echo %~dp0
echo %~d0
pause

You'll see that %~dp0 points to the directory where you script is in, and %~d0 points to the drive letter that it has.

Edit: It ONLY works INSIDE a script file, not in command window.

depp.jones
Offline
Last seen: 1 week 5 days ago
DeveloperTranslator
Joined: 2010-06-05 17:19
I don't know if you

I don't know if you understood the point of Chris' post. The difference between %cd:~0,2% and %~d0 is that the latter is drive independent.
To get the specific drive letter of the USB-drive you have to call your script from a folder of that drive. If you call it from another drive you simply don't get the letter of your USB-drive but the letter of the drive you call it from. It mostly doesn't matter if you start if from a gui, but matters if you call it from a command window or a batch located on another drive.
In the specific case it should work as it typically would be called from the drive itself but it is not failsafe if that changes whereas %~d0 always produces the letter of the drive where the script is located.

In addition to Ph4n70m's post try a script containing

echo %~d0
echo %cd:~0,2%
pause

called (from a commandline) remotely from different drives (as Chris has described) to see the difference.

VIItweaker
Offline
Last seen: 1 year 4 months ago
Joined: 2011-02-20 22:32
...

...

Log in or register to post comments