Pretty simple batch file question for the vets...

warcrow

Lifer
Jan 12, 2004
11,093
11
81
Due to a series of unfortunate events (work politics, I'm sure you guys can understand) I have to impliment am automated system that disables the mounting of USB thumb drives on several loaner machine during their start-up process.

The goods news is I have a working batch file that will do this.

The bad news is actually getting this batch file to run on a few machines before the user logs in.

Since I'm not a programmer of any sorts (I'm mostly a hardware guy), I only have experience with working in Basic--here is what I've come up with so far (hold laughter till the end please):


Once we throw an image on a machine, our level one tech guys run a batch file (migration.bat) that configures, installs and tweaks the machines for our network enviroment. In the batch file (Image_Config.bat) I plan to make a call to our existing USB_Disable.bat file.

That batch, USB_Disable.bat, is suppose to make a comment in the registry to run the last batch file (Perm_Off.bat) so that they're disabled every time the machine is booted up.


Image_Config.bat I have this in there:

"if %computername% == <computername> call c:\migration\SetACL\USB_Reg_Disable.bat"


USB_Reg_Disable.bat:

SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

REG ADD %KEY% /V TITLE /D "USB Drives Disable" /f

REG ADD %KEY%\01 /VE /D "Disable USB Thumb Drives" /f
REG ADD %KEY%\01 /V 1 /D "c:\migration\SetACL\Perm_off.bat" /f



...the problem is that it's not working. I know "Perm_off.bat" works because I've tested it seperately.

Ok, please stop laughing at me now! Help?



For refference, there are 3 batch files:

migration.bat - Runs after an image is pushed.
USB_Reg_Disable.bat - Makes registry entries to make call to perm.bat
Perm_off.bat - disabled the use of USB thumb drives.
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
Wow, nested batch file nightmare! haha....

I'd bet it's a permission problem, depending on what perm_off.bat does - a user does not have permission to edit HKLM i dont believe, so when they log in and it runs it cant remove the key.
 

warcrow

Lifer
Jan 12, 2004
11,093
11
81
Originally posted by: WannaFly
Wow, nested batch file nightmare! haha....

I'd bet it's a permission problem, depending on what perm_off.bat does - a user does not have permission to edit HKLM i dont believe, so when they log in and it runs it cant remove the key.

When I tested this I logged in with my ellevated account.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,244
3,833
75
If I may offer a silly suggestion, do you need more quotes? Like this:

if "%computername%" == "<computername>" call c:\migration\SetACL\USB_Reg_Disable.bat

I believe any spaces in computername would make that necessary.
 

warcrow

Lifer
Jan 12, 2004
11,093
11
81
Originally posted by: Ken g6
If I may offer a silly suggestion, do you need more quotes? Like this:

if "%computername%" == "<computername>" call c:\migration\SetACL\USB_Reg_Disable.bat

I believe any spaces in computername would make that necessary.

We're actually just using the host name (one word), but I'm wondering if I need quotes around the file path?
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
Originally posted by: warcrow
Originally posted by: WannaFly
Wow, nested batch file nightmare! haha....

I'd bet it's a permission problem, depending on what perm_off.bat does - a user does not have permission to edit HKLM i dont believe, so when they log in and it runs it cant remove the key.

When I tested this I logged in with my ellevated account.

right, which would confirm what I'm saying, test it using only a user account.

Post whats in perm_off.bat
 

sao123

Lifer
May 27, 2002
12,648
201
106
surely there is an easier way to accomplish this.

you can right to the registriy to disable USB flash drives with a few lines of MFC (c++ / vb) code... and then just put that EXE in

HKLM/Software/microsoft/windows/currentverison/run
 

warcrow

Lifer
Jan 12, 2004
11,093
11
81
Originally posted by: WannaFly
Originally posted by: warcrow
Originally posted by: WannaFly
Wow, nested batch file nightmare! haha....

I'd bet it's a permission problem, depending on what perm_off.bat does - a user does not have permission to edit HKLM i dont believe, so when they log in and it runs it cant remove the key.

When I tested this I logged in with my ellevated account.

right, which would confirm what I'm saying, test it using only a user account.

Post whats in perm_off.bat

 

warcrow

Lifer
Jan 12, 2004
11,093
11
81
Originally posted by: sao123
surely there is an easier way to accomplish this.

you can right to the registriy to disable USB flash drives with a few lines of MFC (c++ / vb) code... and then just put that EXE in

HKLM/Software/microsoft/windows/currentverison/run

Unfortunately I've never touched C++ or VB.