导航:首页 > 文档加密 > winccvb脚本中怎么加密

winccvb脚本中怎么加密

发布时间:2024-06-08 14:05:04

⑴ 怎样用VB给文件夹进行密码加密

文件或文件夹的加密、解密

'此方法对 WinXP 系统有效,Win98 没试验过。小心:不能用于系统文件或文件夹,否则会使系统瘫痪。
'加密:利用 API 函数在文件或文件夹名称末尾添上字符“..\”。比如,将文件夹“MyPath”更名为“MyPath..\”,在我的电脑中显示的名称就是“MyPath.”。系统会无法识别,此文件或文件夹就无法打开和修改,也无法删除。着名的病毒 Autorun 就是玩的这个小把戏。
'解密:去掉文件或文件夹名称末尾的字符“..\”

'将以下代码复制到 VB 的窗体代码窗口即可
'例子需控件:Command1、Command2、Text1,均采用默认属性设置
Private Const MAX_PATH = 260
Private Type FileTime ' 8 Bytes
LTime As Long
HTime As Long
End Type
Private Type Win32_Find_Data
dwFileAttributes As Long
ftCreationTime As FileTime
ftLastAccessTime As FileTime
ftLastWriteTime As FileTime
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cNameFile As String * MAX_PATH
cAlternate As String * 14
End Type
Private Declare Function MoveFileEx Lib "kernel32" Alias "MoveFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal dwFlags As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpNameFile As String, lpFindFileData As Win32_Find_Data) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As Win32_Find_Data) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Sub Form_Load()
Text1.Text = "C:\MyPath"
Command1.Caption = "解密": Command2.Caption = "加密"
Me.Caption = "目录或文件的加解密"
End Sub
Private Sub Command1_Click()
Call SetPathName(False) '解密
End Sub
Private Sub Command2_Click()
Call SetPathName(True) '加密
End Sub
Private Sub SetPathName(SetMi As Boolean)
Dim nName As String, NewName As String, nSort As String, nCap As String, dl As Long
nName = Trim(Text1.Text)
If Right(nName, 3) = "..\" Then nName = Left(nName, Len(nName) - 3)
If Right(nName, 1) = "\" Then nName = Left(nName, Len(nName) - 1)
If SetMi Then
NewName = nName & "..\"
Else
NewName = nName
nName = nName & "..\"
End If
If SetMi Then nCap = "加密" Else nCap = "解密"
nSort = GetShortName(nName) '转变其中的 ..\
If nSort = "" Then
MsgBox "文件没有找到:" & vbCrLf & nName, vbCritical, nCap
Exit Sub
End If
If MoveFileEx(nSort, NewName, 0) = 0 Then Exit Sub '文件更名:非零表示成功,支持只读文件
MsgBox nCap & "成功:" & vbCrLf & nName, vbInformation, nCap
End Sub
Public Function GetShortName(F As String, Optional ShortAll As Boolean) As String
'转变为短文件名,如果目录或文件不存在就返回空。可用于判断某目录或文件是否存在
'不能直接用 API 函数 GetShortPathName, 因它不支持 ..\
'ShortAll=T 表示全部转变为短名称,否则只转变其中的点点杠“..\”
Dim FondID As Long, ID1 As Long, S As Long, nPath As String
Dim nF As String, InfoF As Win32_Find_Data, qF As String, hF As String
Dim nName As String, nName1 As String

nF = F
Do
S = InStr(nF, "..\")
If S = 0 Then Exit Do
qF = Left(nF, S + 2): hF = Mid(nF, S + 3) '分为前后两部分
CutPathName qF, nPath, nName
nName = LCase(nName)
qF = nPath & "\" & "*."
FondID = FindFirstFile(qF, InfoF) '-1表示失败。查找所有文件(夹)
ID1 = FondID
Do
If FondID = Find_Err Or ID1 = 0 Then GoTo Exit1 '没有找到符合条件的条目

nName1 = LCase(CutChr0(InfoF.cNameFile)) '文件(夹)名称
If nName1 & ".\" = nName Then
nName1 = CutChr0(InfoF.cAlternate) '用短文件名代替
If hF = "" Then nF = nPath & "\" & nName1 Else nF = nPath & "\" & nName1 & "\" & hF
Exit Do
End If
ID1 = FindNextFile(FondID, InfoF) '查找下一个,0表示失败
Loop
FindClose FondID
Loop

Exit1:
FindClose FondID

S = MAX_PATH: nName = String(S, vbNullChar)
ID1 = GetShortPathName(nF, nName, S) '返回实际字节数,0表示失败
If ID1 = 0 Then Exit Function

If ShortAll Then
If ID1 > S Then
S = ID1: nName = String(S, vbNullChar)
ID1 = GetShortPathName(nF, nName, S) '返回实际字节数
End If
GetShortName = CutChr0(nName)
Else
GetShortName = nF
End If
End Function
Public Sub CutPathName(ByVal F As String, nPath As String, nName As String)
Dim I As Long, LenS As Long

LenS = Len(F)
For I = LenS - 1 To 2 Step -1
If Mid(F, I, 1) = "\" Then
nPath = Left(F, I - 1): nName = Mid(F, I + 1)
GoTo Exit1
End If
Next
nPath = F: nName = ""

Exit1:

If Right(nPath, 2) = ".." Then
nPath = nPath & "\"
Else
If Right(nPath, 1) = "\" Then nPath = Left(nPath, Len(nPath) - 1)
End If

If Right(nName, 1) = "\" And Right(nName, 3) <> "..\" Then nName = Left(nName, Len(nName) - 1)
End Sub
Private Function CutChr0(xx As String) As String
Dim S As Long
S = InStr(xx, vbNullChar)
If S > 0 Then CutChr0 = Left(xx, S - 1) Else CutChr0 = xx
End Function
'参考资料见下

⑵ WinCC flexible2008 参数设置画面怎么加密

在你的按钮里面慎御属性里面执行一个系统控件,控宽弯岩件名字为LOG ON,密码在触摸屏程序中的管理员属性里面先设定好,可以分组或不分组闹指权限,然后运行,你试一下看看

阅读全文

与winccvb脚本中怎么加密相关的资料

热点内容
linux硬盘模式 浏览:13
怎么查安卓的空间 浏览:587
linux命令复制命令 浏览:115
劳动法里面有没有带工资算法的 浏览:456
如何在u盘里拷解压软件 浏览:689
oracle数据库登陆命令 浏览:614
python自动化运维之路 浏览:400
eclipsejava教程下载 浏览:987
tita搜索app怎么配置 浏览:263
oracle的连接命令 浏览:1002
基于单片机的恒温水壶 浏览:884
鸿蒙系统文件夹怎么换背景 浏览:296
b站动画算法 浏览:712
程序员每月还房贷 浏览:355
cad墙闭合命令 浏览:168
udp广播可以找到本地服务器地址 浏览:676
加密门卡手机如何复制门禁卡 浏览:266
夜莺的PDF 浏览:707
地方资讯app如何推广 浏览:756
金蝶网络加密连不上 浏览:262