子进程在提示输入密码之前打开程序

时间:2018-07-31 18:02:02

标签: python windows subprocess ssms runas

我正在编写一个脚本,以便在Option Explicit Private Sub Workbook_Open() Dim aFSO As New Scripting.FileSystemObject Dim aFolder As Object Dim aFiles As Object Set aFolder = aFSO.GetFolder("R:\Groups\Finance\Ops Finance\Reporting\F18 Cost Analysis\Standard Costing\Std Cost Variances\Variance Master Back-Ups\") If aFolder Is Nothing Then MsgBox "Directory not found!", vbExclamation: Exit Sub Set aFiles = aFolder.Files Application.StatusBar = "Saving back up copy" ThisWorkbook.SaveCopyAs aFolder.Path & "\" & _ VBA.Replace(ThisWorkbook.Name, ".xlsm", "") & "_copy_" & _ VBA.Format$(Now, "m-d-yyyy hhmmss AM/PM") & ".xlsm" Call CleanUpArchive(aFolder, aFolder.Path & Chr(92), aFiles.Count) Set aFolder = Nothing Set aFSO = Nothing End Sub 'Cleans up archive file by deleting the 11th file (oldest copy) Private Function CleanUpArchive(Folder As Object, Path As String, _ CountofFiles As Integer) Dim aFiles As Scripting.Files Set aFiles = Folder.Files If CountofFiles > 10 Then aFiles(CountofFiles).Delete True End If Set aFiles = Nothing End Function 机器上使用SQL Server Management Studio命令启动runas。从Windows运行时,命令提示用户输入密码,然后启动程序。

cmd

在我的情况下,只要碰到from subprocess import Popen, PIPE user = '/user:some_domain\\username' # \ to escape special character path = 'C:/Program Files (x86)/Microsoft SQL Server/130/Tools/Binn/ManagementStudio/Ssms.exe' process = Popen(['runas', '/netonly', user, path], stdin=PIPE, stdout=PIPE) # launches 'ssms.exe' process.communicate('password\n') # never hit 行,它就会启动process = Popen(...),而不会提示输入密码。 SSMS中的检查过程在两种情况下都显示相同的用户名,因此我不知道它是否在正确的域上运行。我该如何解决?

0 个答案:

没有答案