nagus
Goto Top

Netzlaufwerk mit Benutzer Abfrage und PW verbinden

Moin Zusammen,
ich habe folgendes Problem:
Die GFs müssen an einem Buchhaltungsarbeitsplatz die Zahlungen freigeben. Dies soll jeweils im Kontext des angemeldeten Users passieren. Die Schlüsselsdatei liegt aber auf dem persönlichen Laufwerk des Users, da dies im Programmpfad eingestellt ist. (Sfirm in einer Citrix Umgebung).

Man könnte das ganze ja ganz profan über zwei drei Batch-Scripte machen, aber das ist natürlich nicht so schick face-big-smile
und da die Passworteingaben völlig unsichtbar ablaufen, auch nicht Benutzer freundlich. Deswegen meine Idee: WSH Shell und da hänge ich nun face-sad
Deswegen: HILFE ...

Die Anforderungen:
1. Benutzerabfrage
2. Maskiertes Passwort
3. Es muss ein Laufwerk getrennt werden und ein anderes verbunden werden

Gefunden habe ich bereits:
Benutzername und Passwortabfrage mit dem IE

' This function uses Internet Explorer to  
' create a dialog and prompt for a password.  
   Dim objIE
   ' Create an IE object (I guess you'll have to)  
   Set objIE = CreateObject( "InternetExplorer.Application" )  
   ' specify  the IE  settings  
   objIE.Navigate "about:blank"  
   objIE.Document.Title = "Benutzer wechsel"  
   objIE.ToolBar        = False
   objIE.StatusBar      = False
   objIE.Resizable      = False
   objIE.Width          = 400
   objIE.Height         = 300
   ' Center the dialog window on the screen (front and center!)  
   With objIE.Document.ParentWindow.Screen
       objIE.Left = (.AvailWidth  - objIE.Width ) \ 2
       objIE.Top  = (.Availheight - objIE.Height) \ 2
   End With

    ' Insert the HTML code to prompt for your super secret password'  
    objIE.Document.Body.InnerHTML = "<DIV align='center'><P>" & myPrompt _  
                                & "</P>" & vbCrLf _  
                                & "<div align='center'><font color='red'><P>" & myMessage _  
                                & "</P></font>" & vbCrLf _  
	                            & "<P><INPUT TYPE='input' SIZE= '20'" _  
                                & "ID='Username'/></P>" & vbCrLf _^^  
                                & "<P><INPUT TYPE='password' SIZE= '20'" _  
                                & "ID='Password'></P>" & vbCrLf _  
                                & "<P><INPUT TYPE='hidden' ID='OK'" _  
                                & "NAME='OK' VALUE='0'/></p>" _  
                                & "<INPUT TYPE='submit' VALUE='OK'" _  
                                & "OnClick='VBScript:OK.Value=1'/></P></DIV>"  

    ' Make the window visible (If you must *sigh*)  
    objIE.Visible = True

    ' Wait till the OK button has been clicked (uh huh...)  
    Do While 0 = objIE.Document.All.OK.Value
    	Wscript.Sleep 250
    Loop

	' Read the password from the dialog window (evil thoughts on this method)  
	getUsername = objIE.Document.All.Username.Value
	getPassword = objIE.Document.All.Password.Value

    ' Close and release the object  
    objIE.Quit
    Set objIE = Nothing

Das WSH Script für das Laufwerk verbinden sieht dann etwa so aus:

Netzlaufwerk verbinden

    Set wn = WScript.CreateObject("WScript.Network")  
    'erst trennen  
    wn.RemoveNetworkDrive "U:", True, True  
    'dann mappen  
    wn.MapNetworkDrive "U:", "\\192.168.2.5\Username", False, "Username", "Password"  
   msgbox("Done.")  

1. Parameter: Laufwerksbucstabe
2. Parameter: Zieladresse
3. Parameter: Wiederverbindung beim nächsten Systemstart (true/ false)
4. Parameter: User
5. Parameter: Password

Wie bekomme ich nun das Passwort und die Benutzerkennung in das WSH Script? Hier lassen mich meine geringen Programierkentnisse im Stich.

Wer kann mir helfen, oder hat eine bessere Lösung?

Gruß Nagus

Content-Key: 149338

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

Ausgedruckt am: 28.03.2024 um 11:03 Uhr

Mitglied: bastla
bastla 19.08.2010 um 14:39:03 Uhr
Goto Top
Hallo Nagus!

Wenn beides bereits funktioniert, könnte der letzte Teil des Scripts (ungetestet) einfach so aussehen:
' Read the password from the dialog window (evil thoughts on this method)  
getUsername = objIE.Document.All.Username.Value
getPassword = objIE.Document.All.Password.Value

Set wn = WScript.CreateObject("WScript.Network")  
wn.MapNetworkDrive "t:", "\\192.168.2.5\geheim", False, getUsername, getPassword  

' Close and release the object  
objIE.Quit
Set objIE = Nothing

msgbox "Done."  
Grüße
bastla

P.S.: Scripts bitte als "" formatiert posten ...
Mitglied: Nagus
Nagus 20.08.2010 um 10:22:13 Uhr
Goto Top
Hi bastla,
erst mal Danke für die Hilfe. Leider funktioniert das nicht. grrrr

Der erste Teil des Scriptes ist ja html und steuert den IE. Dann starte ich die WSH Shell hier muss ich doch die Variablen mit & getUsername & übernehmen - richtig? Alles in einer vbs datei. Auch ok?

Wenn ich das dann zusammen bastel, sieht das so aus:

' Read the password from the dialog window (evil thoughts on this method)  
getUsername = objIE.Document.All.Username.Value
getPassword = objIE.Document.All.Password.Value

Set wn = WScript.CreateObject("WScript.Network")  
'Erst das Laufwerk trennen  
wn.RemoveNetworkDrive "U:", True, True  

'und jetzt mappen und hier steckt jetzt wohl der Wurm drin -.-  
wn.MapNetworkDrive "U:", "\\FS-101-185\daten\Docs\**" & getUsername &""**, False, getUsername, getPassword   

' Close and release the object  
objIE.Quit
Set objIE = Nothing
 
msgbox "Done."  

Was mache ich falsch? (jaja - alles - ich weiß ... face-wink

P.S.: Scripts bitte als "" formatiert posten ...
ich hoffe so isses nu richtig - habe leider keine Vorschau.

Gruß
Nagus
Mitglied: bastla
bastla 20.08.2010 um 12:13:58 Uhr
Goto Top
Hallo Nagus!

Gemeint war:
' This function uses Internet Explorer to  
' create a dialog and prompt for a password.  
   Dim objIE
   ' Create an IE object (I guess you'll have to)  
   Set objIE = CreateObject( "InternetExplorer.Application" )  
   ' specify  the IE  settings  
   objIE.Navigate "about:blank"  
   objIE.Document.Title = "Benutzer wechsel"  
   objIE.ToolBar        = False
   objIE.StatusBar      = False
   objIE.Resizable      = False
   objIE.Width          = 400
   objIE.Height         = 300
   ' Center the dialog window on the screen (front and center!)  
   With objIE.Document.ParentWindow.Screen
       objIE.Left = (.AvailWidth  - objIE.Width ) \ 2
       objIE.Top  = (.Availheight - objIE.Height) \ 2
   End With

    ' Insert the HTML code to prompt for your super secret password'  
    objIE.Document.Body.InnerHTML = "<DIV align='center'><P>" & myPrompt _  
                                & "</P>" & vbCrLf _  
                                & "<div align='center'><font color='red'><P>" & myMessage _  
                                & "</P></font>" & vbCrLf _  
	                            & "<P><INPUT TYPE='input' SIZE= '20'" _  
                                & "ID='Username'/></P>" & vbCrLf _^^  
                                & "<P><INPUT TYPE='password' SIZE= '20'" _  
                                & "ID='Password'></P>" & vbCrLf _  
                                & "<P><INPUT TYPE='hidden' ID='OK'" _  
                                & "NAME='OK' VALUE='0'/></p>" _  
                                & "<INPUT TYPE='submit' VALUE='OK'" _  
                                & "OnClick='VBScript:OK.Value=1'/></P></DIV>"  

    ' Make the window visible (If you must *sigh*)  
    objIE.Visible = True

    ' Wait till the OK button has been clicked (uh huh...)  
    Do While 0 = objIE.Document.All.OK.Value
    	Wscript.Sleep 250
    Loop

' Read the password from the dialog window (evil thoughts on this method)  
getUsername = objIE.Document.All.Username.Value
getPassword = objIE.Document.All.Password.Value

Set wn = WScript.CreateObject("WScript.Network")  
wn.MapNetworkDrive "t:", "\\192.168.2.5\geheim", False, getUsername, getPassword  

' Close and release the object  
objIE.Quit
Set objIE = Nothing

msgbox "Done."  
Das gesamte Script ist VBS - HTML wird nur, wie Du schon angemerkt hast, zur Steuerung des IE verwendet; die Kontrolle hat aber weiterhin VBS ...

Grüße
bastla
Mitglied: Nagus
Nagus 20.08.2010 um 13:21:58 Uhr
Goto Top
Hi bastla,

hm - also 100%ig sicher ob ich das richtig verstanden habe ...:
Am Ende soweit ich alles verstanden habe und wie ich es zusammengebastelt habe.

Getrennt wird zwar, aber beim Verbinden gibt es einen Fehler. Laufwerkspfad existiert nicht ...
Wie kann ich mir die getUsername und getPassword ansehen? So richtig?
msgbox("" & getUsername &"")  
Wenn ich noch die Domäne (=DOM) benötige kann ich mir das doch das so definieren:
strUsrDom=""DOM\" & getUsername""  

Schon mal Danke für die Geduld ... !

Gruß
Nagus


' This function uses Internet Explorer to  
	' create a dialog and prompt for a password.  
	
    Dim objIE
    ' Create an IE object (I guess you'll have to)  
    Set objIE = CreateObject( "InternetExplorer.Application" )  
    ' specify  the IE  settings  
    objIE.Navigate "about:blank"  
    objIE.Document.Title = "Benutzer wechsel"  
    objIE.ToolBar        = False
    objIE.StatusBar      = False
    objIE.Resizable      = False
    objIE.Width          = 400
    objIE.Height         = 300
    ' Center the dialog window on the screen (front and center!)  
    With objIE.Document.ParentWindow.Screen
        objIE.Left = (.AvailWidth  - objIE.Width ) \ 2
        objIE.Top  = (.Availheight - objIE.Height) \ 2
    End With

    ' Insert the HTML code to prompt for your super secret password'  
    objIE.Document.Body.InnerHTML = "<DIV align='center'><P>" & myPrompt _  
                                & "</P>" & vbCrLf _  
                                & "<div align='center'><font color='red'><P>" & myMessage _  
                                & "</P></font>" & vbCrLf _  
	                            & "<P><INPUT TYPE='input' SIZE= '20'" _  
                                & "ID='Username'/></P>" & vbCrLf _  
                                & "<P><INPUT TYPE='password' SIZE= '20'" _  
                                & "ID='Password'></P>" & vbCrLf _  
                                & "<P><INPUT TYPE='hidden' ID='OK'" _  
                                & "NAME='OK' VALUE='0'/></p>" _  
                                & "<INPUT TYPE='submit' VALUE='OK'" _  
                                & "OnClick='VBScript:OK.Value=1'/></P></DIV>"  

    ' Make the window visible (If you must *sigh*)  
    objIE.Visible = True

    ' Wait till the OK button has been clicked (uh huh...)  
    Do While 0 = objIE.Document.All.OK.Value
    	Wscript.Sleep 250
    Loop
	' Read the password from the dialog window (evil thoughts on this method)  
	getUsername = objIE.Document.All.Username.Value
	getPassword = objIE.Document.All.Password.Value

    Set wn = WScript.CreateObject("WScript.Network")   
'erst trennen   
    wn.RemoveNetworkDrive "U:", True, True   

'dann mappen - hier funktioniert das nicht: der Pfad zu den Daten lautet eigentlich vollständig \\192.168.101.185\daten\Docs\BENUTZERNAME  
    wn.MapNetworkDrive "U:", "\\192.168.101.185\daten\Docs\" & getUsername &"", False, getUsername, getPassword  

    ' Close and release the object  
    objIE.Quit
    Set objIE = Nothing
Mitglied: bastla
bastla 20.08.2010 um 14:07:21 Uhr
Goto Top
Hallo Nagus!

Ich weiß zwar nicht, weshalb Du unbedingt an die Variable "getUsername" vorne und hinten genau nix anfügen möchtest, aber zur Not ginge es auch mit
msgbox("" & getUsername &"")
Ich bin etwas sparsamer veranlagt und würde nur
msgbox getUsername
schreiben ...

Die zweite Zeile würde bei mir so aussehen:
strUsrDom = "DOM\" & getUsername
Grüße
bastla
Mitglied: Nagus
Nagus 20.08.2010 um 15:35:14 Uhr
Goto Top
Hi bastla,

was soll ich sagen: weil ich keine Ahnung habe und nur solche Lösungen gefunden habe .. face-sad

Ok, jetzt habe ich es aber begriffen. ist ja eigentlich ganz simpel face-wink

Jetzt habe ich nur ein merkwürdiges Problem: wenn das Netzlaufwerk verbunden wird, gibt es einen Fehler das PW wäre falsch. Verbinde ich das LW im Kontext vom Explorer klappt alles.

ich habe mir auch schon das PW per
 msgbox getpassword
angesehen und das ist richtig!

Muss ich die Variable anders wählen, weil ich z.B. ein # im PW habe?

Wenn\'s dann mal komplett läuft poste ich es am Stück für alle interessierten ... face-smile
Mitglied: bastla
bastla 20.08.2010 um 17:23:13 Uhr
Goto Top
Hallo Nagus!

Variablenname und -inhalt haben nix miteinander zu tun - daher sollte
wn.MapNetworkDrive "U:", "\\192.168.101.185\daten\Docs\" & getUsername, False, strUsrDom, getPassword
funktionieren ...

Grüße
bastla