远程重启服务VB 2010 [英] Restarting services remotely VB 2010
问题描述
你好,
我试图找出如何在远程机器上重启某些服务。屏幕有一个输入远程计算机的IP地址或机器名称的位置,然后有一个组合框,其中包含某些服务的列表。我想弄清楚的是在代码中输入的计算机名称或IP地址进入我有textbox1.text的地方,但似乎不适用于它周围的。
我尝试过:
这是我的代码:
Hello,
I am trying to figure out how to restart certain services on remote machines. The screen has a place to input the ip address or machine name of the remote computer and then there is a combobox that has a list of the certain services. What I am trying to figure out is in the code to have the computer name or ip address that is typed in to go in where I have textbox1.text but doesn't seem to work with the "" around it.
What I have tried:
Here is the code I have:
Process.Start("CMD", "/C sc \\Textbox1.text start Spooler")
我也试过:
I have also tried:
Shell("sc \\Textbox1.text start Spooler")
还有其他我想念的东西还是我看错了?任何帮助是极大的赞赏。谢谢
Is there something else I am missing or am I looking at this all wrong? Any help is greatly appreciated. Thank you
推荐答案
在提出问题之前请先进行基础研究,比如使用google。使用ServiceController类
ServiceController类(System.ServiceProcess) [ ^ ]
ServiceController构造函数(String,String)(System.ServiceProcess) [ ^ ]
显然,您的代码运行的帐户将需要所需的权限。
Please do basic research before asking a question such as using google. Use the ServiceController class
ServiceController Class (System.ServiceProcess)[^]
ServiceController Constructor (String, String) (System.ServiceProcess)[^]
Obviously the account your code is running under will need the required permissions.
还有其他我缺少的东西
是的。对字符串如何工作的一个非常基本的理解。
Yes. A very basic understanding of how strings work.
"/C sc \\Textbox1.text start Spooler"
这假设您的网络上有一个服务器,其实际名称为Textbox1.text。我非常怀疑。
这告诉我你没有最小的线索如何工作以及如何将文本框的值转换为字符串。你真的需要从基础开始。我认真地建议你拿起一本关于VB.NET的初学者书并开始研究它。
这行真的应该是
This assumes you have a server on your network with the actual name of "Textbox1.text". I seriously doubt that.
This tells me that you don't have the smallest clue how strings work and how to get the value of a textbox into a string. You really need to start with the basics. I seriousy recommend you pick up a beginners book on VB.NET and start working through it.
This line really should be something along the line of
Dim args = String.Format("/C sc \\{0} start Spooler", Textbox1.Text)
但是,你正在做的事情更加错误。我现在没有时间深入研究这个问题,论坛环境不适合这个。
But, there's a ton more wrong with what you're doing. I don't have the time to dig into that right now and a forum environment isn't the place for this.
这篇关于远程重启服务VB 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!