如何查找wincc某个用户的登录时间

有一个wincc系统,我建立三个用户,甲方要求wincc能够记录某个用户在莫个时段的登录时间,请问这个功能应该如何才能实现?

最佳答案

首先需要一个BOOL型的内部变量Login,在你的登陆界面的登陆按钮上需要做设置,当登陆成功时,需要将这个Login置一,当退出登录时这个Login归零。
然后在全局脚本中做一个VBS脚本程序,程序如下(VBS的):
--------------------------------------------------------------------------------------------
Dim login
Set login=HMIRuntime.Tags ("login")
login.Read
If login.Value  =1 Then
 Dim fso,myfile,pd1,dstr,fname,fname1
 dstr = FormatDateTime(Date)
 fname1="D:\dhWincc\TEXTBIB\vbs.xls"
 fname="E:\data\Login.xls"
 Set fso = CreateObject("scripting.FileSystemObject")
 pd1=fso.FileExists(fname)
  If pd1=0 Then
   Set MyFile = fso.GetFile(fname1)
   MyFile.Copy (fname)
   Dim ObjExcelApp
   Set objExcelApp = CreateObject("Excel.Application")
   objExcelApp.Workbooks.Open fname
   objExcelApp.worksheets ("sheet1").Cells(1, 1).VAlue ="Write time"
   objExcelApp.worksheets ("sheet1").Cells(1, 2).VAlue = "Label"
   objExcelApp.worksheets ("sheet1").Cells(1, 3).VAlue = "Computer"
   objExcelApp.worksheets ("sheet1").Cells(1, 4).VAlue = "User"
   objExcelApp.worksheets ("sheet1").Cells(1, 5).VAlue = "Login&Logout date"
   objExcelApp.worksheets ("sheet1").Cells(1, 6).VAlue = "Login&Logout time"

   objExcelApp.ActiveWorkbook.Save
   objExcelApp.Workbooks.Close
   objExcelApp.Quit
   Set ObjEXceLapp = Nothing
  End If

 Dim ObjExcelApp1
 Set objExcelApp1= CreateObject("Excel.Application")
 objExcelApp1.Workbooks.Open fname  
 Dim j
 j=2
 Do While objExcelApp1.worksheets ("sheet1").Cells(j, 1).VAlue<>"" 
 j=j+1
 Loop
 objExcelApp1.worksheets ("sheet1").Cells(j, 1).VAlue =Now
 objExcelApp1.worksheets ("sheet1").Cells(j, 2).VAlue = "Login:"
 objExcelApp1.worksheets ("sheet1").Cells(j, 3).VAlue = HMIRuntime.Tags("@LocalMachineName").read
 objExcelApp1.worksheets ("sheet1").Cells(j, 4).VAlue = HMIRuntime.Tags("@CurrentUser").read
 objExcelApp1.worksheets ("sheet1").Cells(j, 5).VAlue = HMIRuntime.Tags("logindate").read
 objExcelApp1.worksheets ("sheet1").Cells(j, 6).VAlue = HMIRuntime.Tags("logintime").read

 objExcelApp1.ActiveWorkbook.Save
 objExcelApp1.Workbooks.Close
 objExcelApp1.Quit
 Set ObjEXceLapp1 = Nothing
-------------------------------------------------------------------------------------------
全局脚本的触发器就是Login这个变量了。
这个脚本是把所有登陆信息写到Excel表格里面了,这个脚本改改还可以做为数据存储用。

最后附送一个登陆脚本(C语言的):
#pragma code("useadmin.dll")
#include "PWRT_API.H"
#pragma code()

PWRTLogout(); 
SetTagBit("login",0);

if (PWRTSilentLogin(GetTagChar("user"), GetTagChar("password")))
{
int r;
r=MessageBox(NULL,"Login?","Prompt Dialog Box",MB_YESNO|MB_ICONQUESTION|MB_SYSTEMMODAL);
if (r==6)
{
SetTagChar("logindate",GetTagChar("dates"));  
SetTagChar("logintime",GetTagChar("times"));
SetTagBit("login",1);
SetTagBit("logout",0);
OpenPicture("main.Pdl"); 
}
else
{
PWRTLogout(); 
SetTagBit("login",0);
}
}
else
{
int t;
t=MessageBox(NULL,"Password Error!","Prompt Dialog Box",MB_OK|MB_ICONWARNING|MB_SYSTEMMODAL);
}

提问者对于答案的评价:
这个没有试,不过谢谢啦

原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc184692.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2017年6月29日 下午4:41
下一篇 2017年6月29日 下午4:41

相关推荐