0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

VBScriptで共有フォルダへNET USEで接続方法

Posted at

共有フォルダへNET USEで接続方法

共有フォルダへのアクセスをバッチ処理などのプログラムで実行させることで、作業ミスの減少と作業効率化を図ることができる、共有フォルダへNET USEで接続方法です。
(VBScriptからDOSコマンドを実行する一連の処理)

Sub Main()

'変数宣言の強制
Option Explicit

Dim objShell
Dim dstTargetHost,dstUserName,dstPassword

dstTargetHost = "\\共有フォルダのIP"
dstUserName = "ユーザー名"
dstPassword = "パスワード"

'共有フォルダへNET USEで接続します。
Set objShell = CreateObject("WScript.Shell")
objShell.Run "net use " & dstTargetHost & " " & dstPassword & " /user:" & dstUserName,0,true

objShell.Run "cmd /c " & ×××.exe & " /install /quiet " , 0, true
'👆例:cmdで.exe のインストール処理です。必要に応じて、実行したい処理内容を記述してください。

'共有フォルダへのNET USEの接続を切断します
objShell.Run "net use " & dstTargetHost & " /DELETE",0,true

'生成したオブジェクトを破棄します。
Set objShell = Nothing

End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?