2012-04-29 11 views
1

私はJacobを使ってシステム時刻を変更しようとしています。このメソッドを実行すると例外jacob java-comブリッジ経由でシステム時間を変更する

com.jacob.com.ComFailException取得、

/******************************************************************************* 
* Sets the system time. 
* 
* @param par_sSystemTime String 
*******************************************************************************/ 
public void setSystemTime(String par_sSystemTime) 
{ 
    ActiveXComponent os =null; 
    ComThread.InitMTA(); 
    try 
    { 
     InetAddress address = FoxEnvironment.getRemoteAddress(FoxEnvironment.getLocalHostName()); 
     String connectStr = String.format("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pkt}!\\\\%s\\root\\CIMV2", address.getHostName()); 
     ActiveXComponent wmi = new ActiveXComponent(connectStr); 
     Variant instances = wmi.invoke("InstancesOf", "Win32_OperatingSystem"); 
     Enumeration<Variant> en = new EnumVariant(instances.getDispatch()); 
     os = new ActiveXComponent(en.nextElement().getDispatch()); 
     os.invoke("SetDateTime", par_sSystemTime); 
    } 
    catch(Exception ex) 
    { 
     ex.printStackTrace(); 
     ML.logMsg(MLCon.SERR, null, BaseMessages.GENERAL_UNEXPECTED_ERROR,"setSystemTime(): " + ex); 
    } 
    catch(NoClassDefFoundError ex) 
    { 
     ex.printStackTrace(); 
     ML.logMsg(MLCon.SERR, null, BaseMessages.GENERAL_UNEXPECTED_ERROR,"setSystemTime(): " + ex); 
    } 
    finally 
    { 
     // Release the components 
     if (os != null) 
     { 
      os.safeRelease(); 
      os = null; 
     } 
     ComThread.Release(); 
    } 
} 

:起動の:SetDateTime 出典:SWbemObjectEx 説明:アクセスが拒否されましたが、私は次のような方法を書きました。

誰でもこれを手伝うことができますか?事前に

おかげで、私の前の質問について バレンチノ

答えて

0

一つの詳細。

私は次のメソッドを記述する場合:それは正常に動作しますが、私は、私は、システムの時刻を設定するために、いくつかのより多くの権限が必要と思いますが、私は権限の種類についての手掛かりを持っていない

/******************************************************************************* 
* Gets the system time. 
* 
* @return String 
*******************************************************************************/ 
public String getSystemTime() 
{ 
    String sSystemTime = null; 
    ActiveXComponent os =null; 
    ComThread.InitMTA(); 
    try 
    { 
     InetAddress address = FoxEnvironment.getRemoteAddress(FoxEnvironment.getLocalHostName()); 
     String connectStr = String.format("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pkt}!\\\\%s\\root\\CIMV2", address.getHostName()); 
     ActiveXComponent wmi = new ActiveXComponent(connectStr); 
     Variant instances = wmi.invoke("InstancesOf", "Win32_OperatingSystem"); 
     Enumeration<Variant> en = new EnumVariant(instances.getDispatch()); 
     os = new ActiveXComponent(en.nextElement().getDispatch()); 
     sSystemTime = os.invoke("LocalDateTime"); 
    } 
    catch(Exception ex) 
    { 
     ex.printStackTrace(); 
     ML.logMsg(MLCon.SERR, null, BaseMessages.GENERAL_UNEXPECTED_ERROR,"setSystemTime(): " + ex); 
    } 
    catch(NoClassDefFoundError ex) 
    { 
     ex.printStackTrace(); 
     ML.logMsg(MLCon.SERR, null, BaseMessages.GENERAL_UNEXPECTED_ERROR,"setSystemTime(): " + ex); 
    } 
    finally 
    { 
     // Release the components 
     if (os != null) 
     { 
      os.safeRelease(); 
      os = null; 
     } 
     ComThread.Release(); 
    } 

    return sSystemTime; 
} 

よろしく、

バレンチノ

関連する問題