%~dp0 variable (Full Version)

All Forums >> [Scripting Technologies] >> Batch



Message


phenry194 -> %~dp0 variable (4/28/2008 5:36:00 PM)

OK, dumb question, I know, but I have to ask.  I am trying to utilize the above listed variable to run a batch file from a server.  I have read various information as to where to place this variable.  I have successfully utilized this variable in a local batch file, but I need to utilize it from a batch file on the server.  I have seen several places to put it in the batch file, but have yielded no results.  I have tried %~dp0\\server\share\share\software.exe /switch /switch /switch parameter=item\item\ parameter=\item\.  I have also tried it with the variable right in front of the executable:   \\server\share\share\%~dp0software.exe /switch /switch /switch parameter=item\item\ parameter=\item\.  help????




ndaniels -> RE: %~dp0 variable (4/29/2008 7:55:21 AM)

Inside of a batch file, %0 is the call of the batch file itself.  It may look something like this...

Run from UNC Path:
%0 = "\\server\users\mystuff\Temp\My Test\My Batch File.cmd"
%~0 = \\server\users\mystuff\Temp\My Test\My Batch File.cmd
%~d0 = \\
%~p0 = server\users\mystuff\Temp\My Test\
%~dp0 = \\server\users\mystuff\Temp\My Test\

Run from Mapped Drive:
%0 = "H:\Temp\My Test\My Batch File.cmd"
%~0 = H:\Temp\My Test\My Batch File.cmd
%~d0 = H:
%~p0 = \Temp\My Test\
%~dp0 = H:\Temp\My Test\

Hope that helps.




ndaniels -> RE: %~dp0 variable (4/29/2008 8:14:37 AM)

Oops!  I didn't actually answer your question, did I?  Sorry about that!  The answer should be...

%~dp0software.exe /switch /switch /switch parameter=item\item\ parameter=\item\

...That's assuming that "software.exe" is in the same folder as the batch file.




phenry194 -> RE: %~dp0 variable (4/29/2008 11:20:20 AM)

OK, but since the batch file isn't in the same location as the software.exe it is calling, how does that get handled?  Since I am pushing an sms package, I would prefer not to grab all that software and put it in the same place, because then it would need to get pushed out to all the distribution points, and that hogs up a lot of space.




ndaniels -> RE: %~dp0 variable (4/29/2008 12:53:07 PM)

I have never used SMS for software distribution, so I don't know how much help I'll be in that arena; however, from a batch file perspective, you may run an application from a network share.  Using your example...

"\\server\share\share\software.exe" /switch /switch /switch parameter=item\item\ parameter=\item\

Be aware that the batch file will run in the directory in which it resides, unless it is being launched from a UNC path (or otherwise specified by the "Start In" field of a Shortcut).  If run from a UNC path, the CMD command interpreter will typically default to the Windows directory for execution.  This means that if "software.exe" is dependent upon other files, it will somehow need to know that they are in "\\server\share\share\" and not "C:\Windows" (or wherever the batch file is actually being run from "locally").

Again, I don't really know much about how SMS works, but...  Another point to keep in mind is that you'll want the share to have the correct file level and share level permissions for the batch file to execute it.  Be sure that whatever account SMS uses to launch the batch file and/or application has access to everything it needs (on the destination computer and any servers where software will be pulled from).




vrodrigues -> RE: %~dp0 variable (4/29/2008 2:42:53 PM)

quote:


\\server\share\share\software.exe" /switch /switch /switch parameter=item\item\ parameter=\item\
Be aware that the batch file will run in the directory in which it resides, unless it is being launched from a UNC path (or otherwise specified by the "Start In" field of a Shortcut).  If run from a UNC path, the CMD command interpreter will typically default to the Windows directory for execution.  This means that if "software.exe" is dependent upon other files, it will somehow need to know that they are in "\\server\share\share\" and not "C:\Windows" (or wherever the batch file is actually being run from "locally").


A work around for the last sentence of the quote above use this
PushD \\server\share\share\
start /wait software.exe /switch /switch /switch parameter=item\item\ parameter=\item\
PopD

  • The  PushD - will temporally map a drive to \\server\share\share
  • The Start /wait - Will launch the application and wait for it to terminate. There is gotcha on using this with applications that spawn another process and close the starting process.
  • The PopD - will delete the drive mapping.

Since you are going to share other than the Distribution Point (DP) you will need to use the SMS Software Installation account and insure that it has the correct privileges to the share and files.

Vic




ndaniels -> RE: %~dp0 variable (4/29/2008 6:29:48 PM)

quote:

ORIGINAL: vrodrigues

  • The  PushD - will temporally map a drive to \\server\share\share
  • The PopD - will delete the drive mapping.



Sweet!  You learn something new every day!  [;)]




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.2179871