|
-
November 21st, 2008, 08:00 AM
#1
autorunning .bat file not doing what its ment to!
I have created an autorun.inf on my flash drive (I am not so interested in it autorunning when I plug it in more the feature of changing what happens when you double click on it and being able to add extra right click menu enteries.)
The autorun.inf changes the default action of the drive to running a .bat file.
The .bat file contains a line like START EXPLORER.EXE %CD%
Now that works fine when the .bat file is boubleclicked on but if I double click on the flashdrice on the My Computer screen explorer starts in the system32 directory.
I guess windows is loading the .bat file at the My Computer level and running it there so %CD% gets set to the system32 directory instead of what I expected it would 'decend' onto the flash drive and run the .bat file from there.
Is there any way around this or a way of adding the current drive letter to the autorun.inf file so I dont need the .bat file at all (assuming doing this does not just have the same problem).
-
November 21st, 2008, 05:46 PM
#2
Sort of fixed it
If I change the autorun.inf to this
[AutoRun]
Icon=Autorun.ico
Label="2GB MicroSD Card"
action="Explore"
open=explorer.exe
shell\USB01\command=removedrive "HUAWEI MMC"
shell\USB01=Remove MicroSD Card
where the default action is done with the action/open combination instead of using the additional right click 'shell' part then explorer opens in the device but I would still have the problem if I wanted to do more than one thing and use a .bat file so I am still looking for an answer.
Note :- RemoveDrive V1.9.1 - prepares removable drives for safe removal
Freeware by Uwe Sieber - www.uwe-sieber.de
-
November 21st, 2008, 06:15 PM
#3
Dont think the above is quite true, I have just noticed that if I create enteries that do the built in default things like explorer is shows the builtin options and moves the ones created by me further down the list.
-
November 22nd, 2008, 08:17 AM
#4
Before the "%CD%" would work, you would need to SET an environment variable named CD. For example:set cd=g:
-
November 22nd, 2008, 05:05 PM
#5
 Originally Posted by SpywareDr
Before the "%CD%" would work, you would need to SET an environment variable named CD. For example: set cd=g:
%CD% is a built in variable giving the current directory with its full path, try opening a cmd prompt and typing echo %CD%
so for example you could make a batch file at the top level of a USB stick with the line 'subst x: %CD%' which would mount the current directory (which would be the top of the usb stick) as x:
So I guess what is happening is when I run a batch file from doing a right click at the My Computer level from a menu entry I have added %CD% is set to the system32 directory and not the directory where the .bat file is.
Have a look here http://vistaonwindows.com/environment_variables.html
Last edited by Carenza; November 22nd, 2008 at 05:10 PM.
-
November 23rd, 2008, 05:19 AM
#6
 Originally Posted by Carenza
%CD% is a built in variable giving the current directory with its full path, try opening a cmd prompt and typing echo %CD%
Right, it returns the same info as the command:cd You can change it though to whatever you like though. For example, if I were in say "D:\Foobar" the command:echo %cd% would return:D:\Foobar If I then type the command:set cd=C:\Windows and then type:echo %cd% the info it returns is:C:\Windows To return the CD environment variable back to it's original setting, simply remove your setting with the command:set cd=
 Originally Posted by Carenza
so for example you could make a batch file at the top level of a USB stick with the line 'subst x: %CD%' which would mount the current directory (which would be the top of the usb stick) as x:
Yes, you could do that. But, you'd be banking on the fact that a user doesn't already have a drive X: defined. (I do).
The "top level" of a drive is called the "root directory", (or simply "root"). All drives have a "root directory" ... which is indicated by the first backslash ("\") right after the colon (":") of the drive letter.
When I'm in the "Windows" directory of drive "C:", the prompt shows:C:\WINDOWS> (I.e., I'm one level below the root directory of drive C:, in a directory named "WINDOWS"). Now type:cd \ and the prompt shows:C:\> Since there is nothing between the "\" and ">", it means I am now in the root directory of drive "C:".
To get to the root directory of any drive, no matter how many levels deep you are, simply type:cd \
 Originally Posted by Carenza
So I guess what is happening is when I run a batch file from doing a right click at the My Computer level from a menu entry I have added %CD% is set to the system32 directory and not the directory where the .bat file is.
Right, you need to start from a known position. For example, the command:cd /d c:\ will put you in the root directory of drive C: ... no matter what drive, or directory you happened to land in. (Of course this assumes the end user has a drive C:).
Also, keep in mind that an end user could have set their "CD" environment variable to something other than the Windows default.
-
November 23rd, 2008, 05:33 AM
#7
I suppose the point I am trying to get at is the %CD% line is in a bat file on my usb stick, I dont know what the drive letter is so thats why I use %CD%
Now becuse the .bat file is stored in <drive>:/file.bat I expeted %CD% to always return the <drive> letter no matter where the file is run from.
I guess I need to find a command line utility that return the location of the file it is run in like basename in Unix
-
November 23rd, 2008, 07:04 AM
#8
"basename" removes the prefix, and optional suffix. For example ...
The command:basename /usr/local/bin/gcc returns the string:gcc
The command:basename /usr/local/bin/gcc.sparc .sparc Returns the string:gcc
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|