10 Replies - 30943 Views - Last Post: 27 April 2006 - 01:09 PM Rate Topic: -----

#1 enj316  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 126
  • Joined: 24-March 06

Converting batch file to VB program

Posted 26 April 2006 - 08:48 AM

I have a batch file that I use to deploy files across my small 30 client domain. I want to create a simple VB program to have a button for deploying the files to all machines and also to have the option to deploy only to certain machines.

How do I basic take the batch script and translate it into the VB code?

For example, if my batch script for one machine is....

xcopy e:\palladio\4.0.5301\server\release\*.* \\palladio_srv\c$\palladio\4.0.5301\server /e



How would I code it in VB on the click event of my deploy button?

Is This A Good Question/Topic? 0
  • +

Replies To: Converting batch file to VB program

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 207
  • View blog
  • Posts: 4,812
  • Joined: 23-December 05

Re: Converting batch file to VB program

Posted 26 April 2006 - 09:44 AM

You don't have to translate it, simply launch a script or command directly into a command prompt:
Call Shell("file_or_command here", vbHide)


I used to use this to send messages across my network... oh about 8 years ago (doesn't seem that long ago) it simply calls shell with the argument supplied in the "".
Was This Post Helpful? 0
  • +
  • -

#3 enj316  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 126
  • Joined: 24-March 06

Re: Converting batch file to VB program

Posted 26 April 2006 - 09:46 AM

Cool...so the old system calls work in VB.NET?
Was This Post Helpful? 0
  • +
  • -

#4 enj316  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 126
  • Joined: 24-March 06

Re: Converting batch file to VB program

Posted 26 April 2006 - 10:53 AM

How would I enter a variable into that same system call?

For example,
dim iBuildNum as Integer

Call Shell("rmdir \\palladio\c$\MSHome\iBuildNum /s /q", vbHide)


Was This Post Helpful? 0
  • +
  • -

#5 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 207
  • View blog
  • Posts: 4,812
  • Joined: 23-December 05

Re: Converting batch file to VB program

Posted 26 April 2006 - 02:36 PM

Not too sure about the new version, but it's likely it should still work.
getting a variable may take more work... you may want to consider creating a bat file from text with your variable and saving it as a .bat file, then use the shell command to launch it, you can then delete the files you created in the process. It's not pretty, but to my knowledge it's the easiest way in VB.

Unless someone else knows a better way?
Was This Post Helpful? 0
  • +
  • -

#6 enj316  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 126
  • Joined: 24-March 06

Re: Converting batch file to VB program

Posted 26 April 2006 - 03:08 PM

It would be nice if I could concantenate the variable into the Shell command, but I haven't found a way to do it yet.

I'll ask around here at work. I'm sure someone at Microsoft has an answer, but then again not a lot of them like to share their "advanced" knowledge.

But if anyone on here has an answer I would greatly appreciate it.
Was This Post Helpful? 0
  • +
  • -

#7 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 207
  • View blog
  • Posts: 4,812
  • Joined: 23-December 05

Re: Converting batch file to VB program

Posted 26 April 2006 - 04:18 PM

sorry i can't be of more help, i havne't used VB in a long time.

EDIT:
I've done some reading (i was bored with my studying) and found this for VB.NET, by using the System.Diagnostics.Process.Start as:
Process.Start("cmd.exe", "/C <command> <switches and parameters>")


hopefully you can find a way to make this usefull in your task

If i come across anything else i will post it as well.

*You work for MS?
What exactly do you do/how'd you manage that? :)

This post has been edited by William_Wilson: 26 April 2006 - 04:27 PM

Was This Post Helpful? 0
  • +
  • -

#8 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 207
  • View blog
  • Posts: 4,812
  • Joined: 23-December 05

Re: Converting batch file to VB program

Posted 26 April 2006 - 04:38 PM

Once more:
Shell Environ$("comspec") & " /c xcopy """ & _
Source & """ """ & Destination & """ " & Option, vbHide


this should be what you are looking for :)

Becareful of the /c part if the directory is wrong it will not work, though it should be ok with this in windows. You may also wish to read:
MS support which uses a process instead of shell() as i listed above
Was This Post Helpful? 0
  • +
  • -

#9 enj316  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 126
  • Joined: 24-March 06

Re: Converting batch file to VB program

Posted 27 April 2006 - 11:16 AM

Yes, I work for MS and manage day to day operations of the MS Home of the Future. My expertise is in infrastructure design and network management, but I'm working on becoming more proficient in programming.

Mostly all of our prototypes are written in C++ or C#, but there are a lot of operations tools that I'm trying to create in VB, since it is the language I know the best which isn't great. I would get more help from our dev team but they are really busy all the time. I have to fend for myself.

-Ian
Was This Post Helpful? 0
  • +
  • -

#10 enj316  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 126
  • Joined: 24-March 06

Re: Converting batch file to VB program

Posted 27 April 2006 - 12:22 PM

Sucess at last!!!

Here is what worked for me on this problem....
Process.Start("cmd.exe", "/C md \\mshguest\c$\" & CStr(intBuildNum))



William thanks for all your help. You freakin' ROCK!! :)
Was This Post Helpful? 0
  • +
  • -

#11 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1958
  • View blog
  • Posts: 20,401
  • Joined: 17-March 01

Re: Converting batch file to VB program

Posted 27 April 2006 - 01:09 PM

enj316, glad you found the answer you were looking for.

William, thanks for helping enj316 out!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1