Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to access windows Security Log in java

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article to share with you is about java how to access the windows security log, Xiaobian feel quite practical, so share to everyone to learn, I hope you can read this article after some harvest, not much to say, follow Xiaobian to see it.

//query window log public void queryWindowsData(String ip,String user,String space,String password,String domain){ try { //Create session authentication connection JISession dcomSession =JISession.createSession(domain,user,password); dcomSession.useSessionSecurity(true); JIProgId progId = JIProgId.valueOf("WbemScripting.SWbemLocator"); progId.setAutoRegistration(true); JIComServer comServer = new JIComServer(progId, ip, dcomSession); IJIDispatch wbemLocator = (IJIDispatch) JIObjectFactory.narrowObject(comServer.createInstance().queryInterface(IJIDispatch.IID)); //parameterstoconnecttoWbemScripting.SWbemLocator JIVariant[] results = wbemLocator.callMethodA("ConnectServer", new Object[]{ JIVariant.OPTIONAL_PARAM(), (space == null) ? JIVariant.OPTIONAL_PARAM() : new JIString(space) , JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM() , JIVariant.OPTIONAL_PARAM() , 0 , JIVariant.OPTIONAL_PARAM() }); IJIDispatch wbemServices=(IJIDispatch)JIObjectFactory.narrowObject(results[0].getObjectAsComObject()); //String sql = "SELECT * FROM Win32_ComputerSystem"; SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar cc=Calendar.getInstance(); //utc Time-8 //eventcode = 4769 indicates the user logged in by adding a domain cc.add(Calendar.HOUR_OF_DAY, -9);//1 hour ago, 8 is minus UTC String dateString = sdf.format(cc.getTime()); //WQL query log String QUERY_FOR_ALL_LOG_EVENTS = "Select * from Win32_NTLogEvent Where Logfile = 'Security' and " + "EventCode = '4769' and EventType = 4 and TimeWritten >' "+dateString+"'"; try { results = wbemServices.callMethodA("ExecQuery", new Object[]{new JIString(QUERY_FOR_ALL_LOG_EVENTS), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM()}); IJIDispatch wOSd = (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject()); int count = wOSd.get("Count").getObjectAsInt(); IJIComObject enumComObject = wOSd.get("_NewEnum").getObjectAsComObject(); IJIEnumVariant enumVariant = (IJIEnumVariant) JIObjectFactory.narrowObject(enumComObject.queryInterface(IJIEnumVariant.IID)); IJIDispatch wbemObject_dispatch = null; for (int c = 0; c < count; c++) { Object[] values = enumVariant.next(1); JIArray array = (JIArray) values[0]; Object[] arrayObj = (Object[]) array.getArrayInstance(); for (int j = 0; j < arrayObj.length; j++) { // (IJIDispatch) JIObjectFactory.narrowObject(((JIVariant) arrayObj[j]). wbemObject_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(((JIVariant) arrayObj[j]).getObjectAsComObject()); } String str = (wbemObject_dispatch.callMethodA("GetObjectText_", new Object[]{1}))[0] .getObjectAsString2(); query(str); } } catch (JIException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); }} The above is how to access the Windows security log in java, Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report