当前位置: 主页 > PLC控制

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

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

最佳答案

首先需要一个BOOL型的内部变量Login,在你的登陆界面的登陆按钮上需要做设置,当登陆成功时,需要将这个Login置一,当退出登录时这个Login归零。
然后在全局脚本中做一个VBS脚本程序,程序如下(VBS的):
——————————————————————————————–
Dimlogin
Setlogin=HMIRuntime.Tags("login")
login.Read
Iflogin.Value=1Then
Dimfso,myfile,pd1,dSTr,fname,fname1
dstr=FormatDateTime(Date)
fname1="D:\dhWincc\TEXTBIB\vbs.xls"
fname="E:\data\Login.xls"
Setfso=CreateObject("scripting.FileSystemObject")
pd1=fso.FileExists(fname)
Ifpd1=0Then
SetMyFile=fso.GetFile(fname1)
MyFile.Copy(fname)
DimObjExcelApp
SetobjExcelApp=CreateObject("Excel.Application")
objExcelApp.Workbooks.Openfname
objExcelApp.worksheets("sheet1").Cells(1,1).VAlue="Writetime"
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&Logoutdate"
objExcelApp.worksheets("sheet1").Cells(1,6).VAlue="Login&Logouttime"

objExcelApp.ActiveWorkbook.Save
objExcelApp.Workbooks.Close
objExcelApp.Quit
SetObjEXceLapp=Nothing
EndIf

DimObjExcelApp1
SetobjExcelApp1=CreateObject("Excel.Application")
objExcelApp1.Workbooks.Openfname
Dimj
j=2
DoWhileobjExcelApp1.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
SetObjEXceLapp1=Nothing
——————————————————————————————-
全局脚本的触发器就是Login这个变量了。
这个脚本是把所有登陆信息写到Excel表格里面了,这个脚本改改还可以做为数据存储用。

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

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

if(PWRTSilentLogin(GetTagChar("user"),GetTagChar("pASsword")))
{
intr;
r=MessageBox(NULL,"Login?","PromptDialogBox",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
{
intt;
t=MessageBox(NULL,"PasswordError!","PromptDialogBox",MB_OK|MB_ICONWARNING|MB_SYSTEMMODAL);
}

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

  • 关注微信

猜你喜欢

微信公众号