サンプル投稿用掲示板  VB2005 〜 用トップページ  VB6.0 用 トップページ
- 日時: 2009/12/26 19:06
- 名前: 花ちゃん
  
  - ***********************************************************************************
 * カテゴリー:[通信][他のアプリ関係][]                                        * * キーワード:ネットワーク,シャットダウン,リブート,再起動,強制終了              * *********************************************************************************** 記事No : 11857  投稿日 : 2008/03/21(Fri) 21:19  投稿者 : でん  
  ネットワーク上の他のPCの電源をシャットダウン/リブートしたいのですが、 方法が分かりません。
  ----------------------------------------------------------------------------------- 回答者 : でん ----------------------------------------------------------------------------------- ありがとうございました。 いろいろ参考にして、下記のような関数を作成し実現することができました。
  '///////////////////////////////////////////////////////////////// '  [引数] '    pComputerName :コンピュータ名 or IPアドレス  '    pUserName     :Administrator権限のユーザー名  '    pPassword     :ユーザーのパスワード  '    flg           :0:LogOff 1:Shutdown 2:Reboot 8:PowerOff '  [戻り値] '    0      :正常終了 '    1      :エラー '///////////////////////////////////////////////////////////////// Public Function RemoteShutdown(ByVal pComputerName As String, _                 ByVal pUserName As String, _                                ByVal pPassword As String, _                 ByVal flg As Integer) As Integer
      Dim objOsSet As SWbemObjectSet     Dim objOs As SWbemObject     Dim objLocator As SWbemLocator     Dim objService As Object          On Local Error GoTo ErrorHandler:          Set objLocator = CreateObject("WbemScripting.SWbemLocator")     Set objService = objLocator.ConnectServer(pComputerName, _                        "root\cimv2", _                        pUserName, _                         pPassword)     Set objOsSet = objService.ExecQuery("Select * From Win32_OperatingSystem")          For Each objOs In objOsSet         RemoteShutdown = objOs.Win32Shutdown(flg)     Next          Set objOsSet = Nothing     Set objOs = Nothing     Set objService = Nothing     Set objLocator = Nothing          Exit Function      ErrorHandler:     Err.Clear     RemoteShutdown = 1          Set objOsSet = Nothing     Set objOs = Nothing     Set objService = Nothing     Set objLocator = Nothing      End Function 
  
  
 |