Windows 2016; how do i add to the PATH for something running as a service?

Joined
Jul 26, 2004
Messages
14,115
Location
New Bri-en, CT
1st of all, not a Windows person

Tasked with backing up a SQL dump to a backup device that presents itself as a network drive

The mapped drive needs to be mapped prior to the backup and unmounted after; the mount command is a proprietary command invoking a proprietary technology, so native "map a drive" isn't an option;

I wrote a .BAT file that does the mapping but the service reports "Executed as user: NT Service\SQLSERVERAGENT bla bla bla xxxx is not recognized as an internal or external command, operable program or batch file" Exit code 1"

I figure the exe isn't in the PATH of the service; Can I add that somewhere without adding to the ENV variables for the entire system?

TIA

-Thomas
 
@simple_gifts Can you specify the full file path of the exe that's invoked by the batch file? ie, instead of ping.exe use c:\windows\whatever\ping.exe

JC: The batch file is executed as a prerun script to the SQL backup, so it is executed in the context of a service;

Cpayne; I tried that, but now that i look at it and several hours have passed I might have pointed it to the incorrect directory on the system; I will go back and try that again.
I did modify the .BAT and put in a "cd "C:\Profile Files\xxxx""" in the line prior to the mount command, but what you suggested is clearly the better option.
 
Another way to mount a network path in a batch is to use the PushD and PopD commands.
"Pushd \\ServerName\ShareName\FolderName" ...this will temporarily map and change current directory to the target.
Simply typing "Popd" after the commands are run will evaporate the mapping and return to original directory.

Explicitly mapping using the Net Use command to map an "X" drive for example the next command should be "X:" which changes focus to that drive\PATH. After that the "CD" command changes to different directory if needed.

Not knowing the way you're using the Batch/s limits how to answer this. The Environment you create in a batch other than explicit drive mapping is localized only in that batch or child process and evaporates upon completion.
 
to modify the PATH variable inside a batch environment the SET command will do it
SET PATH=%PATH%;X:\MyFolder

This sets the system PATH and then adds your PATH onto the endafter the semicolon.
 
  • Like
Reactions: JC1
Back
Top