Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,423 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,257 people online right now. Registration is fast and FREE... Join Now!




Problem with variables and shell scripts

 
Reply to this topicStart new topic

Problem with variables and shell scripts

d4t4ch17d
31 Jan, 2008 - 03:11 PM
Post #1

New D.I.C Head
*

Joined: 31 Jan, 2008
Posts: 39


My Contributions
Hello, I am very...VERY new to Visual Basic, but I do a lot of Batch scripting. I wanted to take this to a GUI so I am trying out Visual Basic 2008 Express Edition right now.

I have got down the easy part, designing the interface, now the coding is giving me a migraine.

I am trying to take user input in a textbox and make a variable out of it, and then use that variable in a shell script. That's if what I'm trying to do is even possible.

I have a batch scripted:
CODE

@echo off
set /p computername= Enter Computer Name:
c:\temp\psexec %computername% MsiExec.exe /norestart /q /I{35C03C04-3F1F-42C2-A989-A757EE691F65} REMOVE=ALL

This allows me to remove a program silently and remotely across the domain from the specified computer. Now, as for VB, I am using a Form that has Textbox and a Button. I renamed the Textbox to txtInput1. When I double-click on the Textbox I have this code:
CODE

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInput1.TextChanged

        Dim CompName As Object = txtInput1.Text

    End Sub

When I double-click on the Button I have this code:
CODE

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Shell("cmd /c set /p CompName c:\temp\psexec  %CompName% MsiExec.exe /norestart /q /I{35C03C04-3F1F-42C2-A989-A757EE691F65} REMOVE=ALL
", vbHide)

    End Sub

Of course, what I trying to do is get the user's input in txtInput1.Text to substitute the variable CompName in the shell where %CompName% is.

I am a true novice to coding in general except for simple batch commands. Any help to get me in the right direction is much appreciated!
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Problem With Variables And Shell Scripts
31 Jan, 2008 - 03:27 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,298



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Use the Process.Start method, instead of Shell.

CODE

Dim arguments as String

arguements = "/c set /p CompName c:\temp\psexec " & txtInput1.Text & " MsiExec.exe /norestart /q /I{35C03C04-3F1F-42C2-A989-A757EE691F65} REMOVE=ALL"

Process.Start("cmd.exe", arguments)

User is online!Profile CardPM
+Quote Post

d4t4ch17d
RE: Problem With Variables And Shell Scripts
31 Jan, 2008 - 03:58 PM
Post #3

New D.I.C Head
*

Joined: 31 Jan, 2008
Posts: 39


My Contributions
That code makes a command window open showing me the file path to where my program resides.

I was thinking, is there a way to get VB.NET to perform my batch file without calling the cmd.exe? Like, instead of calling a batch file, can I just code it in VB.NET? If so, what is the syntax for it?

This post has been edited by d4t4ch17d: 31 Jan, 2008 - 03:53 PM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Problem With Variables And Shell Scripts
31 Jan, 2008 - 04:22 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,298



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Just run the batch file directly from the Process.Start method. Be sure to include the entire path to where your batch file is located if it is not stored in the Bin\Debug folder.

CODE
Process.Start("youBatchfile.bat", "Put any arguments here")

User is online!Profile CardPM
+Quote Post

PsychoCoder
RE: Problem With Variables And Shell Scripts
31 Jan, 2008 - 05:08 PM
Post #5

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,477



Thanked: 160 times
Dream Kudos: 9025
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Here is a snippet that performs a shell script that will receive parameters. The snippet performs an XCOPY, but put that aside and look at the logic in the snippet to help you smile.gif
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:10AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month