using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;namespace WindowsFormsApplication4
{public class MultiRunChecker{public static bool hasMultiRun(){Process[] ps = Process.GetProcessesByName(Assembly.GetExecutingAssembly().GetName().Name);if (ps != null && ps.Leng...
将C#的程序的一些用户数据写在一个文件中,并把程序设计为开机启动后,就会出现问题。找不到我的用户数据文件。File.Exists()返回的是false。但是如果手动打开程序又能成功的读取数据文件。 百度了一下也没有找到什么办法,就强制读取文件试一下,而不再用File.Exists()方法判断,结果给我抛出了一个异常:找不到文件:"C:\Windows\SysWOW64\Xxx"。 看了这个错误,估计是64位系统造成了,因为现在做的只是个小程序,没时间在...
1. 启动外部程序,不等待其退出。
2. 启动外部程序,等待其退出。
3. 启动外部程序,无限等待其退出。
4. 启动外部程序,通过事件监视其退出。实现代码如下:// using System.Diagnostics;privatestring appName = "calc.exe";
///<summary>/// 1. 启动外部程序,不等待其退出
///</summary>privatevoid button1_Click(object sender, EventArgs e)
{
Process.Start(appName);
MessageBox.Show(String.Format("外部程序 {0} 启动完...
在实例化Thread的实例,需要提供一个委托,在实例化这个委托时所用到的参数是线程将来启动时要运行的方法。在.net中提供了两种启动线程的方式,一种是不带参数的启动方式,另一种是带参数的启动的方式。不带参数的启动方式如果启动参数时无需其它额外的信息,可以使用ThreadStart来实例化Thread,如下面的代码: 1using System;2using System.Collections.Generic;3using System.Text;4using System.Threading;5 6namespace Console...
RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);//打开注册表子项 key.SetValue(程序的名称, 程序的路径);
或
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath);publicvoid SetAutoRun(string fileName, bool isAutoRun)
{ RegistryKey reg = null; try { if (!System.IO.File.Exists(fil...
C#/WPF/WinForm/.NET程序代码实现软件程序开机自动启动的两种常用方法的示例与源码下载带详细注释-源码代码-注册表方式-启动目录快捷方式C#实现自动启动的方法-两种方法 源码下载地址: https://www.90pan.com/b1908724 必要引用using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using IWshRuntimeLibrary;//添加Com引用"Windows Script Host Object Model" ...
C# winForm启动最小化到任务栏右侧通知栏并交互操作一。主要功能:(1)、程序启动自动隐藏到任务栏右侧通知栏显示。(与系统托盘同义)(2)、双击系统托盘图标显示、隐藏窗口;(3)、右击系统托盘图标提供三个菜单选项,“退出”、“隐藏”、“显示”;二。相关控件:1、建一个WinForm程序—IconForm,将Form属性ShowInTaskbar改为false,这样程序将不会在任务栏中显示。2、将Form属性WindowState选择为
Minimized,以便起来自动最小...
首先,申明两个API///<summary>/// 设置 cookie///</summary>///<param name="lpszUrlName"></param>///<param name="lbszCookieName"></param>///<param name="lpszCookieData"></param>///<returns></returns>[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]publicstaticexternbool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);///<summary>/// 获取cookie...
我有以下问题:
我创建了一个用户控件库(DLL),它只有一个启用的Timer.当我尝试在应用程序中使用此控件时,只要我在设计模式下将其拖动到窗体,它就会开始计数!即使应用程序没有运行….我怎么能避免这种情况?
我的目标是,一旦应用程序启动,Timer就会开始计数,但不会在设计模式下开始计数……因为Timer会使用一些导致设计模式崩溃的外部函数.
先谢谢你!
达里奥解决方法:
Timer_Tick(object sender, EventArgs e)
{if(this.DesignMod...
我正在开发一个c#控制台应用程序,我使用实体框架5.0作为sql server的数据访问层.现在我想跟踪更改并将它们保存在日志表中.所以这样做我发起了2个DbContext对象,一个用于业务数据,另一个用于日志数据,如下所示:class Sync{static void Main(string[] args){string syncResult = "Sync started";Entities entities = new Entities();//for business dataEntities entities2 = new Entities();//for logstry{//code goes hereentitie...
#region 显示程序[DllImport("user32.dll", EntryPoint = "FindWindow")]public static extern int FindWindow(string lpClassName, string lpWindowName);/// <summary> /// 该函数设置由不同线程产生的窗口的显示状态。 /// </summary> /// <param name="hWnd">窗口句柄</param> /// <param name="cmdShow">指定窗口如何显示。查看允许值列表,请查阅ShowWlndow函数的说明部分。</param> /// <returns>如果函数原来可见,返回值为...
//首先要添加 System.ServiceProcess.dll 引用2 ServiceController sc = new ServiceController("MSSQLSERVER");3 4 //判断服务是否已经关闭5 if (sc.Status == ServiceControllerStatus.Stopped)6 {7 sc.Start();8 MessageBox.Show("SQL数据库服务启动成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);9 ...
void Main(string[] args){ServiceController sc = new ServiceController("MSSQL$SQLEXPRESSR2");while (1 == 1){Console.Write("\n\n 可选操作 : \n\n 1.启动数据库服务 2.停止数据库服务 \n\n 开始执行 :");string strQueryState = Console.ReadLine();if (strQueryState.Trim() == "1" && sc.Status.Equals(ServiceControllerStatus.Stopped)){sc.Start();Console.Write("SQL数据库服务启动成功!");}else if (strQueryState.T...
https://www.cnblogs.com/mq0036/p/12117955.html
shell:startup
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\StartupC:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
C#/WPF/WinForm/.NET程序代码实现软件程序开机自动启动的两种常用方法函数的示例与实例带详细注释
方法一:将软件的快捷方式创建到计算机的自动启动目录下(不需要管理员权限)
1.必要引用using System;
us...
// 定时启动一个操作、任务using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;/*
功能:定时启动一个操作。
作者:李茂平
用法:
this.TimeWork = new TimeWork();this.TimeWork.AddWork(new TimeWorkItem()
{
任务名称 = "任务一",
Work ...