如何使用批处理文件运行特定页面或窗口 [英] How to run specific page or windows using batch file
问题描述
大家好,
我有一个程序,其中PageMain.xaml作为启动。现在,我正在添加一个名为Settings.xaml的新窗口,它将用于处理任何配置并存储到app.config文件。当我运行MyApplication.exe时,它将以PageMain.xaml开头。
假设在运行应用程序之前,我想打开设置首先设置配置,完成保存新配置后,我将为主程序运行EXE。有没有办法启动配置窗口?
我有使用批处理文件打开特定表单的脚本。但它适用于WinForms。如何使用WPF执行此操作?下面是WinForms的脚本: -
Hi all,
I have a program which having "PageMain.xaml" as startup. Now, I'm adding new window named "Settings.xaml" where it will be use to handle any configuration and store to "app.config" file. When I'm running a "MyApplication.exe" it will start with "PageMain.xaml".
Let's say before run the application, I want to open the Settings first to set the configuration and after complete save new configuration, I will run the EXE for main program. Is there any way to start the configuration window?
I have the script using batch file to open specific form. But it works on WinForms. How to do this using WPF? Below are the script for WinForms:-
@echo off
start MyWinForm.exe /config
WinForm在程序启动时已经识别,它会看到发送args是否像: -
The WinForm has recognition when program start, it will see if the send the args is like:-
<pre lang="c#">private static void Main(string[] args){
if (args.Length.Equals(0)){
}else if (args.Length.Equals(1) && args[0].ToLower() == "/config"){
}
}
如何在Application_Startup上的VB.Net上执行此操作?
我尝试了什么:
Private Sub Application_Startup(ByVal sender As Object,ByVal e As System.Windows.StartupEventArgs)处理Me.Startup
如果sender.Length.Equals(0)那么
LogEvents(发件人正在发送& sender.Length.Equals(0).ToString,EventLogEntryType.Information)
ElseIf sender.Length.Equals(1)AndAlso sender(0).ToLower()=/ configthen
LogEvents(发件人正在发送& sender(0)。ToLower()。ToString,EventLogEntryType.Information)
Else
LogEvents(发件人发送& sender.Length.Equals(0).ToString,EventLogEntryType.Information)
结束如果
我试过的在'找不到'类型'应用程序'上的前公共成员'长度'时出现异常
How to do it on VB.Net at Application_Startup?
What I have tried:
Private Sub Application_Startup(ByVal sender As Object, ByVal e As System.Windows.StartupEventArgs) Handles Me.Startup
If sender.Length.Equals(0) Then
LogEvents("Sender is sending " & sender.Length.Equals(0).ToString, EventLogEntryType.Information)
ElseIf sender.Length.Equals(1) AndAlso sender(0).ToLower() = "/config" Then
LogEvents("Sender is sending " & sender(0).ToLower().ToString, EventLogEntryType.Information)
Else
LogEvents("Sender is sending " & sender.Length.Equals(0).ToString, EventLogEntryType.Information)
End If
What I have tried goes exception with "Ex-Public member 'Length' on type 'App' not found"
推荐答案
您需要在应用程序中使用Main方法,就像在c#代码中。
Visual Basic中的主要过程 [ ^ ]
或者你可以使用My.Application.CommandLineArgs获取命令行参数
祝你好运!
You would need to have a Main method in your application, just like in the c# code.
Main Procedure in Visual Basic[^]
Or you could get the commandline arguments usingMy.Application.CommandLineArgs
Good luck!
我已经尝试了Nijboer链接并对其进行了更多搜索。这就是我发现的: -
I have try Nijboer link and search a little more about it. And this is what I found:-
Private Sub Application_Startup(ByVal sender As Object, ByVal e As System.Windows.StartupEventArgs) Handles Me.Startup
Try
If e.Args.Length <> 0 Then
Me.StartupUri = New System.Uri("Settings.xaml", System.UriKind.Relative)
ElseIf e.Args.Length = 0 Then
If ComeOnce = False Then
If udt_settings.bDebug = False Then
If CheckIfRunning("explorer") Then
obj_core.KillProcess("explorer")
End If
ChangeDesktopWallpaper()
End If
Me.StartupUri = New System.Uri("PageMain.xaml", System.UriKind.RelativeOrAbsolute)
ComeOnce = True
End If
End If
Catch ex As Exception
LogEvents("Error occur at Application_Startup. Ex-" & Ex.ToString, EventLogEntryType.Information)
End Try
End Sub
所以我制作了2个批处理文件。一个名为exec_program.bat,另一个名为exec_settings.bat。
exec_program.bat脚本: -
So I make 2 batch file. One named exec_program.bat and another one named exec_settings.bat.
exec_program.bat script:-
@echo off
start MyProgram.exe
exec_settings.bat脚本: -
exec_settings.bat script:-
@echo off
start MyProgram.exe /config
它运作良好。很好,感谢帮助/指导。
It just work well. Nice and thanks for help/guide.
这篇关于如何使用批处理文件运行特定页面或窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!