开发者

Periodically shut down a program

开发者 https://www.devze.com 2023-01-13 15:38 出处:网络
I 开发者_开发问答want to kill an executable of a game named KnightOnline and deny user to run it. I\'m using:

I 开发者_开发问答want to kill an executable of a game named KnightOnline and deny user to run it. I'm using:

Process.Start("taskkill.exe", "/f /im kol.exe");

but it's showing a command window. How can I hide the command window, or is there another professional but infamous method to deny an unwanted program?

EDIT: I edited hosts and blocked login page of the game as a solution.


A professional way is to let the user know that some running program may pose conflicts and ask the user to close it before proceeding.

Killing it in silent without even saying "We apologize" is evil.


Would it be better not to allow the user to start the program in the first place?

Windows 2000 and up (XP, Vista, "Seven") have Software Restriction Policies - allows you to set a whitelist or blacklist of programs. In case of a whitelist, only the listed programs will be allowed to start, whereas with the blacklist, all except the listed programs will be allowed. This check happens at the OS level, and cannot be bypassed (except by Administrators). See e.g. this for examples.

(a blacklist is pretty ineffective, as renaming the executable allows running it again; whitelist is more work to get correct and to manage - but most users need at most 20 apps, plus system services)

Note: not all versions of Windows allow the administrators to set Group Policies, IIRC you can't do this in Windows XP Home or in Vista Home Basic.

Also, users will be users: if you block local games, they'll play Flash browser games; if you block Flash, they'll play in-browser Javascript games; if you block that, they'll play pure-HTML text adventure games (while being rightfully pissed that you have incidentally blocked most other websites from functioning).

If you block even that, the users will abandon the computer and go smoking, or bring in cards and play Solitaire IRL, or find a myriad other ways to avoid work (assuming we're talking about office users) - so that's not a win either; unless you're trying to get the user(s) off the computer (as it looks from your comments).


You can use Process.Kill to kill another process:

foreach (var process in Process.GetProcessesByName("kol"))
{
    process.Kill();
}


Try this if you want to run some process in a hidden window:

var processInfo = new ProcessStartInfo() 
                      { 
                         Arguments = "/f /im kol.exe", 
                         FileName = "taskkill.exe", 
                         WindowStyle = ProcessWindowStyle.Hidden 
                      };

Process.Start(processInfo );
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号