myITforum.com Community Forum myITforum.com Community Forum

Home  Forums  Blogs  Live Support chat  Search Articles  Wiki  FAQ  Email Lists  Register  Login  My Profile  Inbox  Address Book  My Subscription  My Forums 

Photo Gallery  Member List  Search  Calendars  FAQ  Ticket List  Log Out

All Forums RSS Feed Subscription:


           



%~dp0 variable

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
  Printable Version
All Forums >> [Scripting Technologies] >> Batch >> %~dp0 variable Page: [1]
Login
Message << Older Topic   Newer Topic >>
%~dp0 variable - 4/28/2008 5:36:00 PM   
phenry194

 

Posts: 148
Score: 0
Joined: 3/30/2007
Status: offline
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????
Post #: 1
RE: %~dp0 variable - 4/29/2008 7:55:21 AM   
ndaniels

 

Posts: 145
Score: 26
Joined: 2/24/2006
From: The Republic of Elbonia
Status: offline
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.

(in reply to phenry194)
Post #: 2
RE: %~dp0 variable - 4/29/2008 8:14:37 AM   
ndaniels

 

Posts: 145
Score: 26
Joined: 2/24/2006
From: The Republic of Elbonia
Status: offline
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.

(in reply to phenry194)
Post #: 3
RE: %~dp0 variable - 4/29/2008 11:20:20 AM   
phenry194

 

Posts: 148
Score: 0
Joined: 3/30/2007
Status: offline
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.

(in reply to ndaniels)
Post #: 4
RE: %~dp0 variable - 4/29/2008 12:53:07 PM   
ndaniels

 

Posts: 145
Score: 26
Joined: 2/24/2006
From: The Republic of Elbonia
Status: offline
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).

(in reply to phenry194)
Post #: 5
RE: %~dp0 variable - 4/29/2008 2:42:53 PM  1 votes
vrodrigues


Posts: 53
Score: 7
Joined: 6/8/2001
Status: offline
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

(in reply to ndaniels)
Post #: 6
RE: %~dp0 variable - 4/29/2008 6:29:48 PM   
ndaniels

 

Posts: 145
Score: 26
Joined: 2/24/2006
From: The Republic of Elbonia
Status: offline
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! 

(in reply to vrodrigues)
Post #: 7
Page:   [1]
All Forums >> [Scripting Technologies] >> Batch >> %~dp0 variable Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.234