Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim appPath As String = My.Application.Info.DirectoryPath.ToString() Dim blnRet As Boolean = False blnRet = RunAs(appPath & "\test.bat", "", "an_administrator", "1234takara") End Sub Public Function RunAs(ByVal strExecName As String, ByVal strArguments As String, Optional ByVal strUserName As String = "", Optional ByVal strPassword As String = "") As Boolean Dim psi As New System.Diagnostics.ProcessStartInfo() Dim p As System.Diagnostics.Process psi.UseShellExecute = True psi.Verb = "runas" psi.FileName = strExecName psi.Arguments = strArguments If strUserName <> "" Then psi.UserName = strUserName Dim pw As New System.Security.SecureString Dim ch As String For Each ch In strPassword.ToCharArray() pw.AppendChar(ch) Next psi.Password = pw psi.UseShellExecute = False End If 'アクセスが許可されている作業ディレクトリを設定する psi.WorkingDirectory = My.Application.Info.DirectoryPath.ToString() RunAs = True Try p = System.Diagnostics.Process.Start(psi) p.WaitForExit() Catch ex As System.ComponentModel.Win32Exception Debug.Print(ex.Message) RunAs = False End Try End Function