1
我試圖用Jacob來改變系統時間。我寫了下面的方法:通過jacob java-com橋改變系統時間
/*******************************************************************************
* 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();
}
}
執行這種方法時,得到的異常
com.jacob.com.ComFailException:都調用:SetDateTime 來源:SWbemObjectEx 說明:拒絕訪問。
任何人都可以提供幫助嗎?
由於提前, 華倫天奴
約我剛纔的問題