访问远程计算机上的共享文件 [英] Access shared file on a remote computer

查看:150
本文介绍了访问远程计算机上的共享文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好人, 

Good evening guys , 

我在一个名为"Testshare"的共享文件夹中有一个文件。位于远程计算机,通过LAN网络连接到我的计算机。我想从我的电脑和电脑中读取该远程文件。我写了一些非常好的c ++代码,但是
有一个问题:

I have a file in a shared folder named"Testshare" located in a remote computer which is connected to my computer by LAN network. I want to read that remote file from my computer & i have written some c++ code that works very well but have one issue :

问题是:远程计算机只有一个用户帐户,比如说"acc1"。 &安培;密码"1234" ,只要用户"acc1",我就可以访问该文件并很好地读取数据。注销,如果该用户登录i
得到非常非常严重的结果,如"Bad Ptr"还有很多奇怪的符号(顺便说一下,两台计算机都位于彼此相邻的两个房间里,所以我多次尝试这个测试,并且在登录acc1时总是无法连接),这是代码

The problem is : The remote computer has only one user account let's say "acc1" & password "1234" , I can access the file and read the data very well as long as the user "acc1" is logged off , if that user is logged on i got very very STRANGE results like "Bad Ptr" and a lot of strange symbols ( by the way both computers are located in two rooms next to each other so i tried that test many times and i always fail to connect when acc1 is logged on) , Here is the code

#include< Windows.h>

#include< fstream>

#include< iostream>

#include< string>

#include< vector>

#include< Wtsapi32.h>

#include< Winnetwk。 h>
$
使用命名空间std;



int main()

{

#include <Windows.h>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <Wtsapi32.h>
#include <Winnetwk.h>
using namespace std;

int main()
{

提前感谢您的帮助

推荐答案

命名空间M.Ismail,

Hi namespace M.Ismail,

感谢您在此处发帖。

>>问题是:远程计算机只有一个用户帐户,例如"acc1"。 &安培;密码"1234" ,只要用户"acc1",我就可以访问该文件并很好地读取数据。注销,如果该用户
登录,我得到非常非常严重的结果,如"Bad Ptr"和很多奇怪的符号

很抱歉,我无法重现你的问题,它在我的vs 2015,win10上运行正常,有和没有相同的用户登录。

Sorry that I couldn't reproduce your problem, it works fine on my vs 2015, win10 with and without the same user log on.

我只是在远程计算机上创建一个共享文件夹。使用远程连接登录和注销。运行代码并读取共享文件。它有效。

I just create a shared folder on remote computer. Use the remote connection to log in and off. Run your code and read the shared file. It works.

因此,我建议您逐步查看文件开头和阅读声明,以了解此问题的根本原因。

So I suggest you check your file opening and reading statements step by step to get the root cause of this issue.

或者您可以尝试使用

WNetAddConnection2(&netrc, NULL, NULL, CONNECT_TEMPORARY);

或CreateFile (< \\\\\\ 2002.168.1.110 \\Testshare \\\txt ")使用默认用户和密码。让Windows处理细节。这更方便。

or CreateFile("\\\\192.168.1.110\\Testshare\\1.txt") to use the default user and password. Let Windows deal with the details. It's more convenience.

希望这可以帮到你。

最好的问候,

Sera Yu


这篇关于访问远程计算机上的共享文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆