[Turn]C# 强制关闭当前程序进程(完全Kill掉不留痕迹)

C#代码  
/// <summary>          
/// 运行DOS命令         
 /// DOS关闭进程命令(ntsd -c q -p PID )PID为进程的ID          
/// </summary>       
/// <param name="command"></param>       
/// <returns></returns>         
 public static string RunCmd(string command)          {           
   //實例一個Process類,啟動一個獨立進
             System.Diagnostics.Process p = new System.Diagnostics.Process();           
     //Process類有一個StartInfo屬性,這個是ProcessStartInfo類,包括了一些屬性和方法,下面我們用到了他的幾個屬性:              
  p.StartInfo.FileName = "cmd.exe";       
    //設定程序名             
 p.StartInfo.Arguments = "/c " + command;   
 //設定程式執行參數          
    p.StartInfo.UseShellExecute = false;    
    //關閉Shell的使用           
   p.StartInfo.RedirectStandardInput = true; 
  //重定向標準輸入            
  p.StartInfo.RedirectStandardOutput = true;
  //重定向標準輸出             
 p.StartInfo.RedirectStandardError = true;   //重定向錯誤輸出
              p.StartInfo.CreateNoWindow = true;        
  //設置不顯示窗口            
    p.Start();   //啟動     
    p.StandardInput.WriteLine(command);       //也可以用這種方式輸入要執行的命令             
p.StandardInput.WriteLine("exit");        //不過要記得加上Exit要不然下一行程式執行的時候會當機               
 return p.StandardOutput.ReadToEnd();        //從輸出流取得命令執行結果       
     }  
 在Program.cs加上如下
C#代码  
static class Program      {      
    /// <summary>          /// 应用程序的主入口点。          /// </summary>        
  [STAThread]         
 static void Main()          {       
       Application.EnableVisualStyles();         
     Application.SetCompatibleTextRenderingDefault(false);   
           Application.Run(new MainForm());             
 //强制关闭进程             
 string exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;         
     string[] exeArray = exeName.Split('\\');              
  FunctionClass.RunCmd("taskkill /im " + exeArray[exeArray.Length-1] + " /f ");       
   }     
 }  

 

转载于:https://www.cnblogs.com/qq1223558/p/3316766.html

C#实现强制关闭当前程序进程 /// /// 运行DOS命令 /// DOS关闭进程命令(ntsd -c q -p PID )PID为进程的ID /// /// /// public static string RunCmd(string command) { //實例一個Process類,啟動一個獨立進程 System.Diagnostics.Process p = new System.Diagno 立即下载

相关推荐

pytorch多层感知机实现假钞识别(完整项目构建)

目录1 项目构建2 超参数设置 config.py3 数据集预处理 preprocess.py4 数据集类构建 dataset_banknote.py5 模型构建 model.py6 训练trainer.py6.1 查看损失曲线7 在测试集上运行 inference.py 1 项目构建 构建项目文件夹Banknote,以及子文件夹与py文件。 名称 作用 data目录 存放原始数据与预处理后切分为训练集、验证机、测试集的数据 log目录 存放训练过程中保存的指标,如损失、精确度等

Demon_LMMan的博客 2030

C# 结束进程的解决方法

结束进程的方法有: 方法一:使用Kill()方法,查找到指定的进程名,然后调用Kill()方法杀死进程; System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("notepad"); foreach (System.Diagnostics.Process p in process) { p.Kill(); } 或者 System.Diagnostics.Process[] myP

^@^lemon tea^@^ 1万+

C# 进阶:打造WinForms中的动态交互式UserControl

本文深入探讨了如何在C# WinForms中创建动态交互式UserControl,以提升桌面应用的用户体验和代码复用性。通过剖析UserControl生命周期、事件体系,并结合一个可拖拽缩放的分割面板实战案例,详细讲解了鼠标键盘事件处理、自定义绘制、状态管理以及性能优化等核心技巧,帮助开发者封装复杂交互逻辑,打造专业级自定义控件。

weixin_29279153的博客 466

C# 强制结束程序

如何在C#中点击右上方的 “X”即可关闭程序所有进程? 想通过点击 “X” 结束进程似乎没有想象中简单。 此时两步走: 首先加入代码: //注释代码用于定位 /*private void button1_TextChanged(object sender, EventArgs e) { } */ private void Form1_FormClosing_1...

weixin_42582241的博客 1904

Android开发必备:TBS腾讯浏览服务静态集成完整指南(附Demo下载)

本文详细解析了Android开发中TBS腾讯浏览服务的静态集成方案,通过对比动态集成,深入剖析了其核心原理与适用场景。文章提供了从环境准备、资源获取、项目配置到代码初始化的完整指南,并重点介绍了WebView与文件预览等高级特性的实战应用。针对集成过程中的常见问题,提供了详尽的排查清单与性能调优建议,旨在帮助开发者构建极致稳定、不依赖网络的WebView与文件预览功能。文末附有经过验证的Demo项目可供下载参考。

earth的博客 373

ADS入门学习笔记——低噪声放大器(2)

1、输入匹配网络; 2、输出匹配网络;

weixin_42126696的博客 5001

C#各种结束进程的方法详细介绍

Process类的CloseMainWindow, Kill, Close Process.CloseMainWindow是GUI程序的最友好结束方式,从名字上就可以看出来它是通过结束主窗体,相当于用户点击窗体的关闭按钮或者按Alt + F4。它的本质就是向主窗体发送WM_CLOSE消息(Process.MainWindowsHandle可以返回主窗体的句柄)。这个可以在.NET Framewo

Carter的菜园子 3293

程序化广告行业(2/89):从程序化广告深挖数据处理技巧

大家好!我一直希望能和大家在技术学习的道路上携手共进,这也是我写这一系列博客的初衷。上次我们一起学习了Python基础的数据处理知识,这次咱们借助一本程序化广告手册,深入挖掘数据处理的更多技巧。这本手册涵盖了程序化广告从概念到技术实现的诸多方面,而其中处处都涉及到数据处理,相信会给我们带来不少收获

yyy173611的博客 4588

C#中退出当前进程的方法

这意味着任何在主线程或其它线程中的工作都将被立即停止,这可能会导致一些未处理的异常、未完成的清理工作或未保存的数据丢失。在某些情况下,更好的做法是允许程序自然结束,让所有的线程都有机会完成它们的工作。这个方法接受一个整数参数,这个参数是程序的退出代码。这个值可以被操作系统或其他调用你的程序的程序所使用,以确定程序为何退出。在这个例子中,如果在执行一些代码时抛出了异常,那么程序会捕获这个异常,将其打印出来,并以一个非零的退出代码退出程序。是在C#中用于立即停止当前进程并返回一个指定的退出代码的方法。

hjm123456q的博客 2118

【WRF数据准备】制备月尺度静态地理数据:LAI、Fpar、LUCC

【WRF数据准备】制备月尺度静态地理数据:LAI、Fpar、LUCC

WW、forever的博客 805

YOLOv13改进策略【Neck】| GSConv+Slim Neck:混合深度可分离卷积和标准卷积的轻量化网络设计

实时检测器架构的轻量级设计GsConv。

Limiiiing的博客 99

C#中WinForm程序退出方法技巧总结

C#中WinForm程序退出方法技巧总结 一、关闭窗体 在c#中退出WinForm程序包括有很多方法,如:this.Close();Application.Exit();Application.ExitThread();System.Environment.Exit(0);等他们各自的方法不一样,下面我们就来详细介绍一下。 1.this.Close();只是关闭当...

dianlum5843的博客 1223

基于Python的FAO农业数据高效爬取与分析实战:从Scrapy到异步爬虫的进阶之路

本文将详细介绍如何使用Python最新技术爬取联合国粮农组织(FAO)的农业数据,涵盖从基础爬虫到高级异步爬虫的完整实现过程。文章包含5000余字的技术解析,提供完整的代码示例,并探讨数据处理与存储的最佳实践。

2201_76125261的博客 245

关闭窗体后,后台还有残留进程

1.程序中有while(1)循环 2.程序中有没退出的线程

Andy20081251的专栏 4366

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

C#关闭进程树

http://blog.csdn.net/ffeiffei/article/details/5897003 Windows并不维护进程间的父子关系链,而是提供了另外一个妥协的办法 - Job对象。你可以自己维护相关的多个进程,或把多个进程放入一个Job对象中,以便统一管理。Windows task manager中"End Process" & "End Process Tree

plean的专栏 896

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

C#中强制关闭某个进程

/// &lt;summary&gt; /// 关闭进程 /// &lt;/summary&gt; /// &lt;param name="processName"&gt;进程名&lt;/param&gt; private void KillProcess(string processName) { Process[] myproc = Process.GetProcess...

hududanyzd 712

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

c#程序强制关闭所有进程方法(转载)

在很多情况下,C#程序在应用程序完成后,因为某些线程任务没完成,所以用户看到程序窗口已经关了,但打开任务管理器会发现进程还在,还占用着资源..有时是因为程序本身没去处理关闭线程而引起的,但也有很多情况是种种原因导至程序中的线程任务长时间卡住,甚至无法结束,在网络程序中更为严重..如遇到这类情况,可以用以下代码,在程序结束操作完成后彻底的关闭程序,释放资源 using System....

weixin_30325971的博客 2133

C# 强制关闭当前程序进程(完全Kill掉不留痕迹)

编辑器加载中... C#代码 /// /// 运行DOS命令 /// DOS关闭进程命令(ntsd -c q -p PID )PID为进程的ID /// /// /// public static string RunCmd(string comman...

weixin_30835649的博客 1196

C# 查找进程,并杀死进程

public bool ThreadExitis(string threadName,bool kill) { //From:www.13le.com bool bo = false; System.Diagnostics.Process[] processList = System.Diagnostics.Process.GetProcesses(); foreach (Sy

网络Online 1939

c#退出应用程序办法

/此方法完全奏效,绝对是完全退出。//前面三种方法都不能很好的退出程序,此方法可以完全退出程序,这个要强制得多。//退出当前线程上的消息循环,并关闭该线程上的所有窗口, 也会失灵。原文链接:https://blog.csdn.net/xiaomianfo/article/details/128821561。//好像只在主线程可以起作用,而且当有线程,或是阻塞方法的情况下,很容易失灵。

IT技术猿猴的博客 3517

如何通过 C# kill 指定进程?

咨询区 robr我用代码动态的打开了一个 IE 进程,参考如下代码:staticvoidMain(string[]args) { Proces...

zls365365的博客 1954

【C#】强制关闭程序或文件的常见方式

在C#中直接强制关闭一个指定文件或者程序并不简单,因为操作系统通常会保护这些操作以确保系统稳定性和用户数据的安全性。你可以通过.NET的System.Diagnostics.Process类来查找并终止一个指定的应用程序。这可以有效地关闭另一个正在运行的程序,但不能直接强制关闭文件(因为文件不是进程)。确保在使用这些技术之前仔细考虑其可能带来的后果,并确保你有正当的理由和适当的权限来执行此类操作。数据完整性:随意地终止进程可能会导致未保存的数据丢失,尤其是在处理大型文件或者长时间运行的任务时。

weixin_42245819的博客 818
上一篇: MySQL查询优化
下一篇: 超级灰色按钮克星1.4.1309.12
weixin_30216561
博客等级 码龄11年 119粉丝 1357原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值