我正在尝试使用 Jacob 来更改系统时间。我写了以下方法:
/*******************************************************************************
* 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 描述:访问被拒绝。
任何人都可以帮助解决这个问题吗?
在此先感谢,华伦天奴