473,854 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Shell() function in vb.net with complex command string

I have been trying for days to send a command to the command prompt
through the shell() function in vb.net. For some reason it is not
working. Here is the code:

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim command As String

command = "systeminfo > C:\temp\sysinfo .txt"

Shell(command, AppWinStyle.Max imizedFocus)
'Process.Start( command)

End Sub

As you can tell I have tried it with Shell() and process.start() . I
have also tried to use double quotes throughout different parts of the
string. When the code executes the command window flashes but the file
is not created. When I paste the command in the command window
everything works fine. Can anyone help?

Nov 21 '05 #1
2 6676

<mi***********@ hotmail.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
I have been trying for days to send a command to the command prompt
through the shell() function in vb.net. For some reason it is not
working. Here is the code:

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim command As String

command = "systeminfo > C:\temp\sysinfo .txt"

Shell(command, AppWinStyle.Max imizedFocus)
'Process.Start( command)

End Sub

As you can tell I have tried it with Shell() and process.start() . I
have also tried to use double quotes throughout different parts of the
string. When the code executes the command window flashes but the file
is not created. When I paste the command in the command window
everything works fine. Can anyone help?


This is a meta-ness problem. The ">" is not an argument to systeminfo, but
rather to the command interpreter. Anyway, to make this work, invoke the
command shell explicitly, telling it to execute the command "systeminfo >
C:\temp\sysinfo .txt" and then exit:

Sub Main()
Dim command As String
command = "cmd /c systeminfo > C:\temp\sysinfo .txt"
Shell(command, AppWinStyle.Max imizedFocus)
'Process.Start( command)
End Sub

You could also just redirect standard output for the program, and skip the
file.

David
Nov 21 '05 #2
"David Browne" <davidbaxterbro wne no potted me**@hotmail.co m> schrieb:
You could also just redirect standard output for the program, and skip the
file.


Sample:

<URL:http://dotnet.mvps.org/dotnet/samples/misc/RedirectConsole .zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
6969
by: none | last post by:
Hello all, I wrote a shell program a few years ago in VB6 that needs to be modified. The problem I have is this: The SysAdmin uses this shell in place of Explorer, so there is no taskbar. When his users run PC Anywhere from the shell, and minimize it, it minimizes to the system tray. With no task bar, there is no system tray, so there is no way to restore the PC Anywhere window. The shell starts PC Anywhere using ShellExecute. I...
0
1758
by: Pedro Werneck | last post by:
Hi, I don't know if I should ask this here or on an emacs group/list. If I choose wrong, please forgive me. I am trying to run pychecker on the current buffer on python-mode using the py-pychecker-run command, but it fails with the "Symbol's function definition is void: read-shell-command" error. I don't know elisp, but seems this is the point where the error occurs: ;; Pychecker (defun py-pychecker-run (command) "*Run pychecker...
8
1333
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland newsgroups I learned that there is a function in stdlib.h called system. int system(const char *command); First question, is the system command ANSI compliant. Because I include <cstdlib> and write std::system(command.c_str()); it looks like an...
2
4551
by: Xah Lee | last post by:
Python Doc Problem Example: os.system Xah Lee, 2005-09 today i'm trying to use Python to call shell commands. e.g. in Perl something like output=qx(ls) in Python i quickly located the the function due to its
14
7681
by: jorntk | last post by:
#include <stdio.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #define MAX 256 #define CMD_MAX 10 char *valid_cmds = " ls ps df "; int main (void) { char line_input, the_cmd; char *new_args, *cp;
3
2087
by: SysSpider | last post by:
Hi guys, I made a program in C (command-line) that prints a character the number of times indicated by the user. But, when I insert '*' (asterisk) as character, it says to me that I've insert more than one character. With '&' (ampersand), it gives me an error. I have no clue with '*', but I think the problem with '&' is related to pointers. ---Source code of chars2.c--- #include <stdio.h>
2
4552
by: jcrouse | last post by:
I apologize for starting another thread but the old one had a weird subject line. Anyways...here is the code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strInput As String = Application.StartupPath & "\CreateMameGamesCFG.bat" If lblMameExePath.Text <> "" Then
4
2389
by: Anastasios Hatzis | last post by:
I'm looking for a pattern where different client implementations can use the same commands of some fictive tool ("foo") by accessing some kind of API. Actually I have the need for such pattern for my own tool (http://openswarm.sourceforge.net). I already started restructuring my code to separate the actual command implementations from the command-line scripts (which is optparser-based now) and have some ideas how to proceed. But probably...
0
2713
by: edurran | last post by:
Hi all, I have spent the last three days on this problem. Looked in many forums and not found the answer as yet. Hopefully ye can help. I have two functions. One works fine, the second does not. First Function Function try1 SET objShell = CreateObject("Wscript.Shell")
0
9750
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11024
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10672
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10740
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10362
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7909
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5937
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.