【发布时间】:2020-03-26 11:48:44
【问题描述】:
我创建了一个脚本,该脚本使用我不提供给用户的特定用户名和密码连接到网络文件夹。此脚本连接到网络文件夹 1 或 2 秒,然后执行操作并断开连接,以确保用户在此之后无法访问网络文件夹。
我在我的开发环境中工作得很好。 我使用 cx_Freeze 将我的 .py 转换为 .exe(我多次将它用于其他小程序)
问题是 .exe 文件只能在我开发应用程序的同一台 PC 上正常工作。在所有其他 PC 上它给我错误:文件“network.py”第 1 行,在 ImportError:DLL 加载失败:Le module spécifié est introuvable(英文,它找不到指定的模块)
我尝试添加win32wnet的DLL。但不工作。
我做错了什么。
查看我的代码和我的导入代码
'''
import win32wnet
import os
import re
# configure initial parameter
shareFolder = "\\\\ultra\\circuit-bgo"
usager = "foo"
motPasse = "foo"
# use win32wnet to create resorce to connect or disconnect
net_resource = win32wnet.NETRESOURCE()
net_resource.lpRemoteName = shareFolder
# try to disconnect to be sure no connection steel exist
try:
win32wnet.WNetCancelConnection2(net_resource.lpRemoteName,0,0)
except:
pass
# create connection to network folder
laConnection = win32wnet.WNetAddConnection2(net_resource, motPasse, usager, 0)
if os.path.exists(net_resource.lpRemoteName):
print("connection réussi")
# do some stuff, like read write and modify some files ( 1 or 2 secondes )
else:
print("connection ÉCHOUÉ")
# opps, connection failed
# disconnect to the network folder. I don't want user can access the folder by itself
try:
win32wnet.WNetCancelConnection2(net_resource.lpRemoteName,0,0)
except:
pass
'''
使用 cx_freeze 导入代码
'''
import os
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
#syspath = "c:\\Python32\\Lib\\site-packages\\win32\\perfmondata.dll"
buildOptions = dict(
packages=['win32wnet'],
excludes=[],
include_files=['perfmondata.dll',]
)
executables = [Executable('network.py', base=base)]
setup(name='TestNetwork',
version='0.1',
options=dict(build_exe=buildOptions),
description='NetWork',
executables=executables
)
'''
当我正常使用 cx_freeze 编译时,我会尝试基本代码
这是一个批处理文件:
cxfreeze.bat "c:/Python32/Scripts/network.py" --base-name=Win32GUI --target-dir C:/Python32/Scripts/Dist_Network --icon c:/Python32/Scripts/Logo。图标
【问题讨论】:
-
请尽量写清楚。
-
对不起,我的英语不好
标签: python-3.x cx-freeze pywin32