.bat file will not run .exe that was downloaded

(imported topic written by carroll91)

Hi,

I have created a batch file to install a wlan profile to our assets. When I run the bat file locally it installs the profile but runs as completed when run through BF.

I downloaded a folder from my C:\drive in the task wizard. The folder contained a wirelessprofile.xml file, a wlan.exe and the .bat file. The .bat file runs but a cmd window on my screen says it cannot locate the wlan.exe file yet the job finishes. Here is the content of the .bat file.

@echo off

echo Grabbing WLAN Interface…

For /F “skip=2 tokens=1,2” %%A IN (‘wlan.exe ei’) Do If “%%A”==“GUID:” set Interface=%%B

echo Adding wlan SSID %~n0

wlan.exe sp %Interface% %~n0.xml

set Interface =

echo.

echo SSID: %~n0 has been configured!

pause

Action relevance form my BF job is:

download http://bigfix.bcferries.corp:52311/Uploads/acbc1530048d2d992746f4b127b08d300d222279/BCFStaffWirelessProfile.tmp

continue if {(size of it = 83135 AND sha1 of it = “acbc1530048d2d992746f4b127b08d300d222279”) of file “BCFStaffWirelessProfile.tmp” of folder “__Download”}

extract BCFStaffWirelessProfile.tmp

run __Download\bcfstaff.bat

Any help is appeciated.

Thanks,

Carroll.

(imported comment written by jessewk)

Hi Carroll,

Does BCFStaffWirelessProfile.tmp contain wlan.exe?

I think you might want to reference it with a full path. Does this work?

prefetch name=BCFStaffWirelessProfile.tmp sha1=acbc1530048d2d992746f4b127b08d300d222279 size=83135 url=http://bigfix.bcferries.corp:52311/Uploads/acbc1530048d2d992746f4b127b08d300d222279/BCFStaffWirelessProfile.tmp

extract BCFStaffWirelessProfile.tmp

createfile until END_CREATE
@echo off

echo Grabbing WLAN Interface…
For /F “skip=2 tokens=1,2” %%A IN (‘wlan.exe ei’) Do If “%%A”==“GUID:” set Interface=%%B

echo Adding wlan SSID %~n0
"{pathname of client folder of current site}__Download\wlan.exe" sp %Interface% %~n0.xml
set Interface =

echo.
echo SSID: %~n0 has been configured!
END_CREATE

delete __Download\bcfstaff.bat
move __createfile __Download\bcfstaff.bat
waithidden __Download\bcfstaff.bat

Couple of notes:

  • I moved your download statement to the top and changed it to a prefetch. Downloads always happen first so it’s a good idea to put them up top.

  • I changed from download to prefetch. Prefetch is a newer syntax that’s easier to author than download/continue if. It also better denotes that the download will happen first.

  • I changed the action to write out the batch script so I could use relevance substitution to insert the local path to wlan.exe.

  • I removed the ‘pause’ from the end of your script so it won’t require user interaction

  • I used ‘waithidden’ instead of ‘run’ to avoid showing UI to the end user and to make sure the script completes before the action finishes.

Jesse

(imported comment written by carroll91)

Jesse, Thanks for getting back to me so quickly. I was not able to run the action script. When I went to save it I received an Invalid Action Script/Unable to parse action script for Action1 line 1: Download name is invalid. Wlan.exe is in the tmp folder in BF.

Thanks,

Carroll.

(imported comment written by jessewk)

Uggg… sorry. I mixed up the argument syntax for ‘prefetch’ and the newer ‘add prefetch item’ . Really wish we’d made them the same.

Try replacing the prefetch statement with this line:

prefetch BCFStaffWirelessProfile.tmp sha1:acbc1530048d2d992746f4b127b08d300d222279 size:83135 url=http://bigfix.bcferries.corp:52311/Uploads/acbc1530048d2d992746f4b127b08d300d222279/BCFStaffWirelessProfile.tmp

(imported comment written by carroll91)

Jesse,

Thanks. This is an interesting one. I run the script and it says completed. I don’t get any echo statements and the SSID doesn’t get installed although it will if I run the bat file outside of BF. I’m going to definitely post this SSID export/import for others as it’s been a bear for me and I am certain there are alot of people who would like to do a wlan profile import outside of AD.

Completed prefetch BCFStaffWirelessProfile.tmp sha1:acbc1530048d2d992746f4b127b08d300d222279 size:83135 url=http://bigfix.bcferries.corp:52311/Uploads/acbc1530048d2d992746f4b127b08d300d222279/BCFStaffWirelessProfile.tmp

Completed extract BCFStaffWirelessProfile.tmp

Completed createfile until END_CREATE

Completed @echo off

Completed

Completed echo Grabbing WLAN Interface…

Completed For /F “skip=2 tokens=1,2” %%A IN (‘wlan.exe ei’) Do If “%%A”==“GUID:” set Interface=%%B

Completed

Completed echo Adding wlan SSID %~n0

Completed “{pathname of client folder of current site}__Download\wlan.exe” sp %Interface% %~n0.xml

Completed set Interface =

Completed

Completed echo.

Completed echo SSID: %~n0 has been configured!

Completed END_CREATE

Completed delete __Download\bcfstaff.bat

Completed move __createfile __Download\bcfstaff.bat

Completed waithidden __Download\bcfstaff.bat

Thanks,

Carroll.

(imported comment written by jessewk)

You may need to run the batch script in the user context rather than the client context. Search the forum for RunAsCurrentUser.exe and you’ll find lots of examples.

(imported comment written by carroll91)

Jesse,

Just a quick question. I can copy the wlan, xml, bat files to all the local machines to a temp folder. Can I launch the bcfstaff. bat file on the local machines (2000 of them) via BF. If that is possible I can remove the files via BF after the profile has been launched.

Relavence: exists file “bcfstaff.bat” of folder “C:\Temp”

Action: waithidden “C:\Temp\bcfstaff.bat”

Thanks,

Carroll.

(imported comment written by jessewk)

Hi Carroll,

Generally I wouldn’t recommend that route. Usually BigFix is the most efficient distribution mechanism, but if it’s easy for you and you don’t anticipate delivery issues, there’s nothing wrong with your technique. You can easily execute the batch file with the command you suggest. You still might need to use RunAsCurrentUser to get your expected behavior.

Jesse

(imported comment written by carroll91)

Thanks Jesse. I would rather use BF to run the job but after numerous attempts even using current user I cannot get it to run although it says completed. I think it is having issues making the wlan ei call. Interesting enough when I try to launch the bat file from the local machine via BF it starts as running in BF and stays in that state, even running as currwent user. I think I may have stumped the panel.

Carroll.

(imported comment written by carroll91)

This is the bat file and relevance script that works. Useful for getting profiles out to laptops in bulk without using AD/EAP.

@echo off

cd C:\Temp

echo Grabbing WLAN Interface…

For /F “skip=2 tokens=1,2” %%A IN (‘wlan.exe ei’) Do If “%%A”==“GUID:” set Interface=%%B

echo Adding wlan SSID %~n0

wlan.exe sp %Interface% %~n0.xml

set Interface =

echo.

echo SSID: %~n0 has been configured!

pauseprefetch RunAsCurrentUser.exe sha1:5512ef51a98dff1aa910a8189a0361c161fa703f size:212992 http://software.bigfix.com/download/bes … -2.0.2.exe

download http://bigfix.bcferries.corp:52311/Uploads/c679901d4efe936ec4870d0a5b526eeed6d03e28/BCFStaffWirelessProfile.tmp

continue if {(size of it = 83016 AND sha1 of it = “c679901d4efe936ec4870d0a5b526eeed6d03e28”) of file “BCFStaffWirelessProfile.tmp” of folder “__Download”}

extract BCFStaffWirelessProfile.tmp

waithidden cmd.exe /C copy /Y __Download*.* C:\Temp

wait __Download/RunAsCurrentUser.exe --w “C:\Temp\bcfstaff.bat”

Cheers,

Carroll.