找答案的高端用户(找答案钻石及双钻级别的用户)将尽可能从此问题下的所有回
答中,为您推荐最佳答案。届时您可以根据推荐数采纳答案。
如果自提问时间起7天内您仍无法选出最佳答案,您可以选择“无满意答案”关闭此问题。
小程序查看
手机扫码追踪该问题
手机扫码追踪该问题,
觉得实用,立即去分享!
点击复制链接
首先需要一个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);
}
首次回答问题,获得
双倍西币积分!
立即成为技术知识分享的一员!
找答案微信小程序
提问
搜索
欢迎您访问支持中心!
丰富的视频,全方位的文档,大量的网友交流精华……
为了更好的完善这些内容,我们诚邀您在浏览结束后,花20秒左右的时间,完成一个用户在线调查!
感谢您的支持!