emeriks
Goto Top

VB.Net - Prozess als anderer Benutzer

Hi,
ich stehe gerade auf dem Schlauch. Habe das sicher schon mal gebraucht, finde es aber gerade nicht.

Wenn ich mit VB.Net eine BAT/CMD oder PS1 starte, dann kann ich das Konsolenfenster verstecken, solange ich den Prozess unter der selben Anmeldung starte.
Gebe ich aber abweichende Anmeldedaten mit, dann kommt in jedem Fall das Konsolenfenster. Irgendwas habe ich vergessen, ich komme aber gerade nicht drauf ...

Was muss ich außer den "WindowStyle", "CreateNoWindow" und "UseShellExecute" noch setzen?

Gerne auch mit dem Holzhammer .... face-wink

E.

                Dim µScriptPath As String = ......   '<----- Pfad zum Script  
                Dim µDataFilePathAs String = ......   '<----- Pfad zu Daten  
                Dim µCred As NetworkCredential = gDatabase.GetReportCred()     '<----- Liefert die Anmeldedaten  

                Dim µP As New Process
                With µP
                  With .StartInfo
                    If µCred IsNot Nothing Then
                      .Domain = µCred.Domain
                      .UserName = µCred.UserName
                      .Password = µCred.SecurePassword

                      .WindowStyle = ProcessWindowStyle.Hidden
                      .CreateNoWindow = True
                      .UseShellExecute = False

                    Else
                      .WindowStyle = ProcessWindowStyle.Hidden
                      .CreateNoWindow = True
                      .UseShellExecute = False

                    End If

                    .WorkingDirectory = New FileInfo(µScriptPath).DirectoryName

                    Select Case µScriptPath.Split(".").Last.ToLower  
                      Case "cmd", "bat"  
                        .FileName = "cmd.exe"  
                        .Arguments = String.Format("""{0}"" ""{1}""", µScriptPath, µDataFilePath)  
                      Case "vbs"  
                        .FileName = "cscript.exe"  
                        .Arguments = String.Format("""{0}"" ""{1}""", µScriptPath, µDataFilePath)  
                      Case "ps1"  
                        .FileName = "powershell.exe"  
                        .Arguments = String.Format("-executionpolicy bypass -file ""{0}"" ""{1}""", µScriptPath, µDataFilePath)  
                      Case "exe"  
                        .FileName = µScriptPath
                        .Arguments = String.Format("""{0}""", µDataFilePath)  
                    End Select

                  End With

                  .Start()
                  .WaitForExit()
                End With

Content-Key: 362753

Url: https://administrator.de/contentid/362753

Printed on: April 19, 2024 at 10:04 o'clock

Member: eisbein
eisbein Jan 30, 2018 updated at 05:06:14 (UTC)
Goto Top
Hallo!

Evtl. hilft dir folgender Link weiter: (Workaroud zu ShowInTaskbar)

https://social.msdn.microsoft.com/Forums/en-US/90b6f3fd-f5ab-4e8d-ad0d-a ...

Gruß
eisbein
Mitglied: 135333
135333 Jan 30, 2018 updated at 09:31:42 (UTC)
Goto Top
Gebe ich aber abweichende Anmeldedaten mit, dann kommt in jedem Fall das Konsolenfenster.
Nicht weiter verwunderlich:
ProcessStartInfo.CreateNoWindow Property
Auszug:
Remarks

If the UseShellExecute property is true or the UserName and Password properties are not null, the CreateNoWindow property value is ignored and a new window is created.
Mit Win32-API und der Shell32.dll Methode ShowWindow einfach Prozess verstecken.

Gruß snap