Need help making a shortcut to a FOR command in Windows 7

MasterGoa

New member
Hey guys, been trying for a couple of hour to no avail...

I need to setup this line of code:

for /f "tokens=3 delims=: " %i in ('iscsicli SessionList ^| find "Session Id"') do iscsicli LogoutTarget %i

Do be executable as Administrator with a shortcut.
The context is that with the laptop over Wifi, when I shutdown,
Windows 7 shuts down networking before closing it's drives.
So the disk array I purchased which I use over iSCSI times out because
the connection is attempting to be closed after wifi has been shutdown.
So I would like the above command to be an icon on the desk top to
disconnect the iSCSI drive before I shutdown the laptop.

Any suggestions appreciated.
 
It says &&i is unexpected at this time.

But that line works in an elevated CMD, I need it to work as a application
or batch that I could launch from a shortcut...
 
%i works in a cmd line, %%i is for use in a batch file. I use a very similar line to manage remotely mounted veracrypt containers on my server.
 
How do you launch the batch file?

Can you make that batch file into an exec?
Do I have to put /user:Administrator in the batch?
 
Can I just put that line in a batch and convert it?

Please understand I am not a coder and this does not come naturally to me...
 
If your batch file works, the program I linked can automatically convert and compile it to an executable, you can actually right click on a .bat file and convert to exe. The big limitation with the free version is that the executable only works on the machine you converted it on. That, and anti-virus/anit-malware do not like the encrypted executables it makes.

Though if you are not doing anything special that requires an actual exe, batch files are just fine to use how they are.
 
If your batch file works, the program I linked can automatically convert and compile it to an executable, you can actually right click on a .bat file and convert to exe. The big limitation with the free version is that the executable only works on the machine you converted it on. That, and anti-virus/anit-malware do not like the encrypted executables it makes.

Though if you are not doing anything special that requires an actual exe, batch files are just fine to use how they are.

the only thing special I need is for it to be "clickable".
So click on the shortcut, execute the command in elevated mode, then shutdown the laptop...
 
Double-click works on .bat files. If you need elevated mode, you can either right click on it and choose "run as administrator", or place the batch file somewhere safe, and create a shortcut to it and put that on your desktop. You can then choose "run as administrator" in the shortcut file's properties-compatibility tab. You can also place shutdown /s at the end of the script which will automatically shutdown the pc once the script has been run.

You can fully automate this through gpedit or task scheduler, but that is a different topic for now.
 
Back
Top