導航:首頁 > 編程語言 > vbnet運行程序

vbnet運行程序

發布時間:2023-05-01 20:27:54

Ⅰ vb.net做安裝包,安裝後自動運行程序

1 新建安裝部署項目

打開VS2005,點擊新建項目,選擇:其他項目類型->安裝與部署->安裝向導(安裝項目),然後點擊確定。

2 安裝向導

關閉後打開安裝向導,點擊下一步,或者直接點擊完成。

3 開始製作

安裝向導完成後即可進入項目文件夾:

雙擊"應用程序文件夾"在右邊的空白處右擊,選擇添加->文件,將你的做的應用程序的可執行文件和相應的類庫和組件添加進來。然後右擊你的文件,創建快捷方式,然後把快捷方式分別復制或剪切到左邊的"用戶的'程序'菜單"和"用戶桌面"中。這樣安裝程序安裝完成後會在 "開始->所有程序"和"桌面"上生成程序的快捷方式。也可以直接在"用戶的'程序'菜單"和"用戶桌面"相應目錄下新建快捷方式,然後定位到你的文件。

然後右擊左邊的"應用程序文件夾"打開屬性對話框:將屬性中的"DefaultLocation"的路徑中的"[Manufacturer]"去掉,不然的話做好的安裝程序默認安裝目錄會是"C:\Program Files\你的用戶名\安裝解決方案名稱";

然後打開解決方案管理器,右擊你的解決方案名稱,選擇屬性:打開的屬性頁中,選擇"系統必備", 在打開的系統必備頁中,在"指定系統必備安裝組件的位置"中選中如下選擇項:從與我的應用程序相同的位置下載系統必備組件。選上以後,在生成的安裝文件包中包含.NetFramework組件 。好了,這樣就完成99%了,然後點擊"生成->生成解決方案",生成成功!

我以前參考過的,希望對你有幫助。

http://hi..com/rivers811/blog/item/1fae4716820ced4c20a4e9ef.html

http://hi..com/xw010203/blog/item/90f66603b0f61e8fd43f7ca2.html

安裝完成後自動啟動程序

1.新建一個空的項目InstallCompenent,步驟為:解決方案->右鍵添加->新建項目->選擇"空項目"->輸入名稱"InstallCompenent"->確定,完成項目的添加.

2.在InstallCompenent項目中右鍵->添加->新建項->選擇安裝程序類->輸入名稱"Installer",完成installer類的添加.

修改代碼為:
/// <summary>
/// 功能是做安裝項目主項目輸出
/// 實現安裝過程中的一些操作
/// 如:安裝完成後啟動項目
/// </summary>
[RunInstaller(true)]
public partial class Installer : Installer
{
/// <summary>
/// 應用程序入口
/// </summary>
public static void Main()
{
}
/// <summary>
/// 構造函數
/// </summary>
public ECSuitsInstaller()
{
InitializeComponent();
}
/// <summary>
/// 重寫安裝完成後函數
/// 實現安裝完成後自動啟動已安裝的程序
/// </summary>
/// <param name="savedState"></param>
protected override void OnAfterInstall(IDictionary savedState)
{
base.OnAfterInstall(savedState);
Assembly asm = Assembly.GetExecutingAssembly();
string path = asm.Location.Remove(asm.Location.LastIndexOf("\\")) + "\\";
System.Diagnostics.Process.Start(path + "\\ECSuits.exe");
}
/// <summary>
/// 重寫安裝過程方法
/// </summary>
/// <param name="stateSaver"></param>
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
}
/// <summary>
/// 重寫安裝之前方法
/// </summary>
/// <param name="savedState"></param>
protected override void OnBeforeInstall(IDictionary savedState)
{
base.OnBeforeInstall(savedState);
}
/// <summary>
/// 重寫卸載方法
/// </summary>
/// <param name="savedState"></param>
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
}
/// <summary>
/// 重寫回滾方法
/// </summary>
/// <param name="savedState"></param>
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
}

3.在安裝項目中右鍵->添加項目輸出->選擇"項目"->InstallCompenent.

完成主輸出項目的添加.

4.打開自定義操作編輯器,在安裝->右鍵->添加自定義操作->選擇"應用程序文件夾"->選擇"主輸出來自InstallCompenent",完成添加.

Ⅱ vb net只運行一個程序

方法一:通過Diagnostics.Process.GetProcessesByName函數來檢測程序是否已經啟動

Imports System.Windows.Forms

Mole Mole1
Sub Main()
'檢測多重弊碧啟動
If Diagnostics.Process.GetProcessesByName( _
Diagnostics.Process.GetCurrentProcess.ProcessName).Length > 1 Then
MessageBox.Show("已經一個實例的本程序正在運行。")
Return
End If
Application.Run(New Form())
End Sub
End Mole

不過這個方法有個缺點,如果用臘稿戶輪卜孝改了下exe的名字就檢測不到了,所以更好的方法如下

方法2:使用Mutex

Imports System.Windows.Forms

Mole Mole1
Sub Main()
Dim createdNew As Boolean
' 創建mutex
Dim mutex As System.Threading.Mutex = _
New System.Threading.Mutex(True, "YourAppName", createdNew)
If createdNew = False Then
MessageBox.Show("已經一個實例的本程序正在運行。")
Return
End If

Application.Run(New Form())

' 釋放mutex
mutex.ReleaseMutex()
End Sub
End Mole

Ⅲ 簡述在vb中,運行程序的方法有哪些

vb中運行程序的方法,指的是啟動自身程序嗎?如果是有以下方法可以啟動程序:
1、按快捷鍵F5
2、頂部標准菜單中的啟動按鈕,也就是那個黑色三角行
3、頂部菜單中的運行--啟動
4、編譯為exe,運行。

Ⅳ vb.net運行所在目錄的應用程序並加參數

可試試下面的方法:
1.可接收參數的外部程序
/// <summary>
/// 可接收參數的外部程序主函數
/// </summary>
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] paras)
{
string temp = "";
foreach (string str in paras)
{
temp += str + ",";
}
MessageBox.Show(temp);
Application.EnableVisualStyles();
Application.(false);
Application.Run(new Form1());
}
}

2.啟動外部程序的方法(給外部程序加參數)
/// <summary>
/// 調用外部程序窗體
/// </summary>
public partial class Invokeprogram : Form
{
public Invokeprogram()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.FileName = Application.StartupPath + "\\WindowsFormsApplication1.exe";
proc.StartInfo.Arguments = "-steam -game cstrike"; //傳入啟動參數
proc.Start();
//string output = proc.StandardOutput.ReadToEnd();
// MessageBox.Show(output);
}
}

Ⅳ vb.net 怎麼判斷當前程序是否正在運行

Imports System.Runtime.InteropServices
Mole Mole1
Sub Main()
Dim instance As Process = RunningInstance()
If instance IsNot Nothing Then
ShowWindowAsync(instance.MainWindowHandle, 3) '調用api函數,正常顯示窗口
Return
End If
Dim F1 As New Form1
Application.Run(F1) '顯示窗體
End Sub
<DllImport("User32.dll")>
Public Function ShowWindowAsync(ByVal hWnd As System.IntPtr, ByVal cmdShow As Integer) As Boolean
End Function
Private Function RunningInstance() As Process '返回進程中已經打開的程序
Dim current As Process = Process.GetCurrentProcess()
Dim processes As Process() = Process.GetProcessesByName(current.ProcessName)
For Each process As Process In processes
If process.Id <> current.Id Then
If process.MainMole.FileName = current.MainMole.FileName Then
Return process
End If
End If
Next
Return Nothing
End Function
End Mole

閱讀全文

與vbnet運行程序相關的資料

熱點內容
更新後版本英文怎麼說 瀏覽:267
桌面雲配置文件分離 瀏覽:505
iphone5如何升級4g網路 瀏覽:5
團購是在哪個app 瀏覽:897
打開多個word文檔圖片就不能顯示 瀏覽:855
騰訊新聞怎麼切換版本 瀏覽:269
app安裝失敗用不了 瀏覽:326
桌面文件滑鼠點開會變大變小 瀏覽:536
手機誤刪系統文件開不了機 瀏覽:883
微信兔子甩耳朵 瀏覽:998
android藍牙傳文件在哪裡 瀏覽:354
蘋果6s軟解是真的嗎 瀏覽:310
c語言代碼量大 瀏覽:874
最新網路衛星導航如何使用 瀏覽:425
以下哪些文件屬於圖像文件 瀏覽:774
zycommentjs 瀏覽:414
確認全血細胞減少看哪些數據 瀏覽:265
文件有哪些要求 瀏覽:484
cad打開時會出現兩個文件 瀏覽:65
什麼是轉基因網站 瀏覽:48

友情鏈接