Running a command in power shell profile script has different behaviour than command line
then I run cmd /c net use h: /d
from the powershell command line it all succeeds
but when I run t开发者_JAVA技巧he same command in the powershell $profile script it asks for a manual confirmation.
Anyone know how to prevent the confirmation please?
I cannot find a way to force the net program to force the drive deletion, however I can use the following powershell script to control the Windows Script Host to
map a drive:
(New-Object -ComObject WScript.Network).MapNetworkDrive("H:", '\\SVNAS301\blah')
remove a mapping
(New-Object -ComObject WScript.Network).RemoveNetworkDrive("H:")
Or remove a mapping with force
(New-Object -ComObject WScript.Network).RemoveNetworkDrive("H:", 1)
(New-Object -ComObject WScript.Network).RemoveNetworkDrive("H:", 1, 1)
The second 1 at the end I believe is for bUpdateProfile. The drive would not disappear from the Explorer window unless that value was there.
精彩评论