【发布时间】:2016-08-27 12:45:13
【问题描述】:
我想在VB中执行一个子文件夹中的.bat来重命名一些文件。文件夹是dinamyc,子文件夹的名称是静态的。
path = System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
Dim psi As New ProcessStartInfo(path & "\subfolder\kappa.bat")
这会在我 start.exe 时产生一个错误*,而且这不会做任何事情
Shell(CreateObject("Wscript.Shell").CurrentDirectory & "\subfolder\" & "kappa.bat", AppWinStyle.Hide)
path 变量在我尝试时显示超出我的需要
MessageBox.Show(path)
http://image.prntscr.com/image/e0398d6e69ff48ce80fd826cced03612.png
所以
path
不是我需要的,但我没有找到与我的问题相关的任何内容
编辑:也试过这个
Dim psi As New ProcessStartInfo(path & "\subfolder\kappa.bat")
psi.RedirectStandardError = True
psi.RedirectStandardOutput = True
psi.CreateNoWindow = False
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.UseShellExecute = False
Process.Start(psi)
但是path & "\subfolder\kappa.bat会在执行中生成偏移量并出错
The `GetExecutingAssembly` error is :
System.IO.FileNotFoundException: File not found.
at Microsoft.VisualBasic.Interaction.Shell(String PathName, AppWinStyle Style, Boolean Wait, Int32 Timeout)
at Patcher.Form1.BTN_Click(Object sender, EventArgs e) in D:\Patcher\Form1.vb:line 58
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1080.0 built by: NETFXREL3STAGE
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
Patcher
Assembly Version: 4.0.0.0
Win32 Version: 4.0.0.0
CodeBase: file:///D:/Patcher.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 10.0.0.0
Win32 Version: 14.6.1038.0 built by: NETFXREL2
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1081.0 built by: NETFXREL3STAGE
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1038.0 built by: NETFXREL2
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1038.0 built by: NETFXREL2
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1078.0 built by: NETFXREL3STAGE
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1038.0 built by: NETFXREL2
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1064.2 built by: NETFXREL3STAGE
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1038.0 built by: NETFXREL2
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
【问题讨论】:
-
您的问题缺少很多信息,在目前的状态下,这使得它非常模糊。如果您没有给我们足够的信息,您不能指望我们提供帮助,例如:
this will generate an error- 这是什么错误,它说什么? --the path varible show more than I need- 那么它显示了什么以及您希望它显示什么? -
@VisualVincent more than I need 意味着这将是一个像 file\c:\.. 这样的字符串,所以不是 C:\\ 并且错误是当我执行程序并告诉我一个偏移量跨度>
-
您可以直接从您的程序中重命名文件,而不是使用 .bat 文件。请参阅File.Move Method。这将更有效,可能更容易编程,并消除对外部文件的依赖。
-
@AndrewMorton 我需要多次执行此操作,我不能这么快地重命名 20k 文件,我想用 vba 重命名它们,但看起来很复杂,用 .bat 更快我只需要执行它以某种方式
-
@AndrewMorton 对不起先生,我删除了它,并添加了我使用的所有代码
标签: vb.net shell batch-file directory