導航:首頁 > 文檔加密 > 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腳本中怎麼加密相關的資料

熱點內容
spring如何添加app 瀏覽:664
python循環import 瀏覽:552
怎樣把js代碼加密 瀏覽:800
frp伺服器百度雲 瀏覽:792
12306演算法 瀏覽:630
單片機驅動小馬達 瀏覽:100
pythoncookbook27 瀏覽:518
c的指針和python 瀏覽:186
python寫sftp 瀏覽:957
讀文pdf 瀏覽:507
pythonnumpy內積 瀏覽:782
linux硬碟模式 瀏覽:15
怎麼查安卓的空間 瀏覽:589
linux命令復制命令 瀏覽:115
勞動法裡面有沒有帶工資演算法的 瀏覽:456
如何在u盤里拷解壓軟體 瀏覽:689
oracle資料庫登陸命令 瀏覽:616
python自動化運維之路 瀏覽:402
eclipsejava教程下載 瀏覽:989
tita搜索app怎麼配置 瀏覽:265