Sign in to follow this  
Followers 0
shornw

Login script

8 posts in this topic

hi all

Is there an AutoIt command that can identify the .bat filename that calls a script.

We have about 40 Logonscripts, some of which are redundant, and I want to identify which are being used. I can do it by creating a seperate log for each one but it would be much easier to have just one log file.

@ScriptName calls the name of the script running but I need the name of the file that has called the script.

Any help always appreciated

Thx


[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites



Why don't you call the script with parameter %filename of batch%?

Then you can use in the script '$CmdLine[]' to get the filename from calling batch.

Share this post


Link to post
Share on other sites

Sorry if I'm being thick here but I dont quite understand what you mean. could you explain a little more.

Thanks


[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites

you could retrieve the parent process ID of the running process with WMI. However, the parent process name will allways be cmd.exe in case of a batch file, so you won't get the name of the calling batch file.

Sample of my test (I ran process.exe from run.bat).

Caption: process.exe

CommandLine: process.exe

Name: process.exe

ParentProcessId: 5904

ProcessId: 2696

Caption: cmd.exe

Name: cmd.exe

ParentProcessId: 3652

ProcessId: 5904

Better do this:

Add the following line at the beginning of each batch file and then analyze the log.

echo %DATE% - %TIME% - %0% >> \\serverxzy\logs\batch-execute.log

Users must have write access to that file !!

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Sorry if I'm being thick here but I dont quite understand what you mean. could you explain a little more.

Thanks

what he means is:

run.bat:

AutoITScript.exe %0%

This will call your compiled AutoIT script with the name of the batch file. Then you can write that name into a log within the AutoIT script.

AutoITScript.au3:

$calling_batch = $CmdLine[1]

FileWriteLine("C:\bitches.log",$calling_batch)

!! You'll have to add some error checking as well !!

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Guys...what can I say. Absolutely fantastic...all these years of IT and i didnt know about the %0%

All done and working...

Thank you so much, this will make life a lot easier for me


[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites

what he means is:

run.bat:

AutoITScript.exe %0%

This will call your compiled AutoIT script with the name of the batch file. Then you can write that name into a log within the AutoIT script.

AutoITScript.au3:

$calling_batch = $CmdLine[1]

FileWriteLine("C:\bitches.log",$calling_batch)

!! You'll have to add some error checking as well !!

Cheers

Kurt

I couldn't help but note the irony. :D

Amp Energy Drink: the official sponsor of me scripting at 2AM.

Share this post


Link to post
Share on other sites

I couldn't help but note the irony. :whistle:

that was intentional!

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

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  
Followers 0